diff --git a/src/main/java/BZip2.java b/src/main/java/BZip2.java index 4bacf82..3d73136 100644 --- a/src/main/java/BZip2.java +++ b/src/main/java/BZip2.java @@ -1,27 +1,73 @@ import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; +/** + * {@link BZip2} itself is an implementation of {@link InputStream} to feed the header magic to a {@link BZip2CompressorInputStream}. + * + * @see #decompress(byte[], int, int, byte[]) + */ public class BZip2 extends InputStream { private static final byte[] MAGIC = {'B', 'Z', 'h', '1'}; - public static void decompress(byte[] dst, byte[] src, int srcOff, int srcLen) throws IOException { - BZip2CompressorInputStream bz2in = new BZip2CompressorInputStream(new BZip2(src, srcOff, srcLen)); + /** + * Decompresses the source. + * + * @param src the source data. + * @param off the source offset. + * @param len the source length. + * @param dst the destination or null 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(); + } + + BZip2CompressorInputStream in = new BZip2CompressorInputStream(new BZip2(src, off, len)); + byte[] buf = new byte[2048]; int read; int written = 0; - while ((read = bz2in.read(buf)) != -1) { - System.arraycopy(buf, 0, dst, written, read); + + while ((read = in.read(buf)) != -1) { + if (tmp != null) { + tmp.write(buf, 0, read); + } else { + System.arraycopy(buf, 0, dst, written, read); + } written += read; } + + if (tmp != null) { + return tmp.toByteArray(); + } + + return dst; } + /** + * 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); } diff --git a/src/main/java/Draw2D.java b/src/main/java/Draw2D.java index 61424fc..454c93a 100644 --- a/src/main/java/Draw2D.java +++ b/src/main/java/Draw2D.java @@ -1,6 +1,6 @@ import java.util.Arrays; -public class Draw2D extends DoublyLinkedList.Node { +public class Draw2D { public static int[] pixels; public static int width; diff --git a/src/main/java/FileArchive.java b/src/main/java/FileArchive.java index aff10d7..76e1143 100644 --- a/src/main/java/FileArchive.java +++ b/src/main/java/FileArchive.java @@ -25,7 +25,7 @@ public class FileArchive { if (packedSize != unpackedSize) { data = new byte[unpackedSize]; - BZip2.decompress(data, src, 6, packedSize); + BZip2.decompress(src, 6, packedSize, data); buffer = new Buffer(data); unpacked = true; } else { @@ -65,7 +65,7 @@ public class FileArchive { byte[] dst = new byte[fileSizeInflated[file]]; if (!unpacked) { - BZip2.decompress(dst, data, fileOffset[file], fileSizeDeflated[file]); + BZip2.decompress(data, fileOffset[file], fileSizeDeflated[file], dst); } else { System.arraycopy(data, fileOffset[file], dst, 0, fileSizeInflated[file]); } diff --git a/src/main/java/Image24.java b/src/main/java/Image24.java index 351821a..8de36e3 100644 --- a/src/main/java/Image24.java +++ b/src/main/java/Image24.java @@ -1,12 +1,8 @@ -// Decompiled by Jad v1.5.8f. Copyright 2001 Pavel Kouznetsov. -// Jad home page: http://www.kpdus.com/jad.html -// Decompiler options: packimports(3) - import java.awt.*; import java.awt.image.PixelGrabber; import java.io.IOException; -public class Image24 extends Draw2D { +public class Image24 extends DoublyLinkedList.Node { public int[] anIntArray1439; public int anInt1440; diff --git a/src/main/java/Image8.java b/src/main/java/Image8.java index e3db305..cb46508 100644 --- a/src/main/java/Image8.java +++ b/src/main/java/Image8.java @@ -1,7 +1,3 @@ -// Decompiled by Jad v1.5.8f. Copyright 2001 Pavel Kouznetsov. -// Jad home page: http://www.kpdus.com/jad.html -// Decompiler options: packimports(3) - import java.io.IOException; public class Image8 { diff --git a/src/main/java/Scene.java b/src/main/java/Scene.java index 4bf5d36..71670a4 100644 --- a/src/main/java/Scene.java +++ b/src/main/java/Scene.java @@ -3,6 +3,7 @@ // Decompiler options: packimports(3) import java.util.Arrays; +import java.util.LinkedList; public class Scene {