This commit is contained in:
thedaneeffect committed 2023-01-07 20:15:43 -05:00
1 parent ed6390f148
commit 2e7e22aced
55 files changed
+9627 -9613

No files matched your search

+64 -64
View File
@@ -13,79 +13,79 @@ import java.io.InputStream;
*/
public class BZip2 extends InputStream {
private static final byte[] MAGIC = {'B', 'Z', 'h', '1'};
private static final byte[] MAGIC = {'B', 'Z', 'h', '1'};
/**
* @see #decompress(byte[], int, int, byte[])
*/
public static byte[] decompress(byte[] src) throws IOException {
return decompress(src, 0, src.length, null);
}
/**
* @see #decompress(byte[], int, int, byte[])
*/
public static byte[] decompress(byte[] src) throws IOException {
return decompress(src, 0, src.length, null);
}
/**
* @see #decompress(byte[], int, int, byte[])
*/
public static byte[] decompress(byte[] src, int off, int len) throws IOException {
return decompress(src, off, len, null);
}
/**
* @see #decompress(byte[], int, int, byte[])
*/
public static byte[] decompress(byte[] src, int off, int len) throws IOException {
return decompress(src, off, len, null);
}
/**
* Decompresses the source.
*
* @param src the source data.
* @param off the source offset.
* @param len the source length.
* @param dst the destination or <code>null</code> to create a new one.
* @throws IOException if the stream content is malformed or an I/O error occurs.
*/
public static byte[] decompress(byte[] src, int off, int len, byte[] dst) throws IOException {
ByteArrayOutputStream tmp = null;
/**
* Decompresses the source.
*
* @param src the source data.
* @param off the source offset.
* @param len the source length.
* @param dst the destination or <code>null</code> to create a new one.
* @throws IOException if the stream content is malformed or an I/O error occurs.
*/
public static byte[] decompress(byte[] src, int off, int len, byte[] dst) throws IOException {
ByteArrayOutputStream tmp = null;
if (dst == null) {
tmp = new ByteArrayOutputStream();
}
if (dst == null) {
tmp = new ByteArrayOutputStream();
}
try (BZip2CompressorInputStream in = new BZip2CompressorInputStream(new BZip2(src, off, len))) {
if (tmp != null) {
IOUtils.copy(in, tmp);
} else {
IOUtils.readFully(in, dst);
}
}
try (BZip2CompressorInputStream in = new BZip2CompressorInputStream(new BZip2(src, off, len))) {
if (tmp != null) {
IOUtils.copy(in, tmp);
} else {
IOUtils.readFully(in, dst);
}
}
if (tmp != null) {
return tmp.toByteArray();
}
if (tmp != null) {
return tmp.toByteArray();
}
return dst;
}
return dst;
}
/**
* The input.
*/
private final ByteArrayInputStream in;
/**
* The position.
*/
private int position;
/**
* The input.
*/
private final ByteArrayInputStream in;
/**
* The position.
*/
private int position;
/**
* Constructs a new helper class to fool that silly compressor.
*
* @param src the source.
* @param off the source offset.
* @param len the source length.
*/
private BZip2(byte[] src, int off, int len) {
this.in = new ByteArrayInputStream(src, off, len);
}
/**
* Constructs a new helper class to fool that silly compressor.
*
* @param src the source.
* @param off the source offset.
* @param len the source length.
*/
private BZip2(byte[] src, int off, int len) {
this.in = new ByteArrayInputStream(src, off, len);
}
@Override
public int read() throws IOException {
if (position < 4) {
return MAGIC[position++];
}
return in.read();
}
@Override
public int read() throws IOException {
if (position < 4) {
return MAGIC[position++];
}
return in.read();
}
}