do not copy big byte arrays, store only references (ByteArrayRange) e.g in image tags

This commit is contained in:
honfika@gmail.com
2014-11-09 22:40:36 +01:00
parent 270cc40856
commit 3456d04d38
151 changed files with 2787 additions and 2512 deletions

View File

@@ -696,6 +696,25 @@ public class SWFInputStream implements AutoCloseable {
return ret;
}
/**
* Reads byte range from the stream
*
* @param count Number of bytes to read
* @param name
* @return ByteArrayRange object
* @throws IOException
*/
public ByteArrayRange readByteRangeEx(long count, String name) throws IOException {
if (count <= 0) {
return ByteArrayRange.EMPTY;
}
newDumpLevel(name, "bytes");
int startPos = (int) getPos();
skipBytesEx(count);
endDumpLevel();
return new ByteArrayRange(swf.uncompressedData, startPos, (int) count);
}
/**
* Reads bytes from the stream
*
@@ -718,6 +737,19 @@ public class SWFInputStream implements AutoCloseable {
return ret;
}
/**
* Skip bytes from the stream
*
* @param count Number of bytes to skip
* @throws IOException
*/
public void skipBytesEx(long count) throws IOException {
bitPos = 0;
for (int i = 0; i < count; i++) {
readNoBitReset();
}
}
/**
* Skip bytes from the stream
*
@@ -726,10 +758,7 @@ public class SWFInputStream implements AutoCloseable {
*/
public void skipBytes(long count) throws IOException {
try {
bitPos = 0;
for (int i = 0; i < count; i++) {
readNoBitReset();
}
skipBytesEx(count);
} catch (EOFException | EndOfStreamException ex) {
logger.log(Level.SEVERE, null, ex);
}
@@ -769,7 +798,7 @@ public class SWFInputStream implements AutoCloseable {
InflaterInputStream dis = new InflaterInputStream(new ByteArrayInputStream(data));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
if (count > 0) {
byte[] buf = new byte[4096];
byte[] buf = new byte[4096];
int c = 0;
while ((c = dis.read(buf)) > 0) {
baos.write(buf, 0, c);