RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
CompressionUtil.java
1package com.osroyale.fs.util;
2
3import com.osroyale.fs.cache.FileSystem;
4import org.apache.tools.bzip2.CBZip2InputStream;
5
6import java.io.ByteArrayInputStream;
7import java.io.IOException;
8import java.util.zip.GZIPInputStream;
9
10import static com.google.common.io.ByteStreams.toByteArray;
11
39
40* A static-utility class containing containing extension or helper methods for
41 * <b>co</b>mpressor-<b>dec</b>compressor<b>'s</b>.
42 * @author Ryley Kimmel <ryley.kimmel@live.com>
43 */
44public final class CompressionUtil {
45
52 public static byte[] gunzip(byte[] data) throws IOException {
53 return toByteArray(new GZIPInputStream(new ByteArrayInputStream(data)));
54 }
55
71 public static byte[] unbzip2Headerless(byte[] data, int offset, int length) throws IOException {
72 /* Strip the header from the data. */
73 byte[] bzip2 = new byte[length + 2];
74 bzip2[0] = 'h';
75 bzip2[1] = '1';
76 System.arraycopy(data, offset, bzip2, 2, length);
77
78 /* Uncompress the headerless data */
79 return unbzip2(bzip2);
80 }
81
88 public static byte[] unbzip2(byte[] data) throws IOException {
89 return toByteArray(new CBZip2InputStream(new ByteArrayInputStream(data)));
90 }
91
98 private CompressionUtil() {
99 throw new UnsupportedOperationException("static-utility classes may not be instantiated.");
100 }
101
102}