diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFInputStream.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFInputStream.java index dc0d13438..2ee2234fb 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFInputStream.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFInputStream.java @@ -297,6 +297,8 @@ public class SWFInputStream implements AutoCloseable { private static final Logger logger = Logger.getLogger(SWFInputStream.class.getName()); + private static final byte[] BYTE_ARRAY_EMPTY = new byte[0]; + private final List listeners = new ArrayList<>(); private long percentMax; @@ -694,7 +696,7 @@ public class SWFInputStream implements AutoCloseable { */ public byte[] readBytesEx(long count, String name) throws IOException { if (count <= 0) { - return new byte[0]; + return BYTE_ARRAY_EMPTY; } newDumpLevel(name, "bytes"); byte[] ret = readBytesInternalEx(count); @@ -730,7 +732,7 @@ public class SWFInputStream implements AutoCloseable { */ private byte[] readBytesInternalEx(long count) throws IOException { if (count <= 0) { - return new byte[0]; + return BYTE_ARRAY_EMPTY; } bitPos = 0; @@ -787,7 +789,7 @@ public class SWFInputStream implements AutoCloseable { */ public byte[] readBytes(int count, String name) throws IOException { if (count <= 0) { - return new byte[0]; + return BYTE_ARRAY_EMPTY; } newDumpLevel(name, "bytes"); byte[] ret = new byte[count]; @@ -805,17 +807,23 @@ public class SWFInputStream implements AutoCloseable { } public byte[] readBytesZlib(long count, String name) throws IOException { + if (count == 0) { + return BYTE_ARRAY_EMPTY; + } + newDumpLevel(name, "bytesZlib"); byte[] data = readBytesInternalEx(count); endDumpLevel(); + return uncompressByteArray(data); + } + + public static byte[] uncompressByteArray(byte[] data) throws IOException { InflaterInputStream dis = new InflaterInputStream(new ByteArrayInputStream(data)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); - if (count > 0) { - byte[] buf = new byte[4096]; - int c = 0; - while ((c = dis.read(buf)) > 0) { - baos.write(buf, 0, c); - } + byte[] buf = new byte[4096]; + int c = 0; + while ((c = dis.read(buf)) > 0) { + baos.write(buf, 0, c); } return baos.toByteArray(); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFOutputStream.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFOutputStream.java index 08df1bf8b..d1e51a1be 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFOutputStream.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFOutputStream.java @@ -1783,6 +1783,14 @@ public class SWFOutputStream extends OutputStream { deflater.finish(); } + public static byte[] compressByteArray(byte[] data) throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DeflaterOutputStream deflater = new DeflaterOutputStream(baos, new Deflater(9)); + deflater.write(data); + deflater.finish(); + return baos.toByteArray(); + } + /** * Reads one BITMAPDATA value from the stream *