mirror of https://github.com/apache/poi.git
bug 52949,59830: move module storage and decompressing into a standalone function
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1751987 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
50e4a82230
commit
c220067619
|
@ -172,6 +172,39 @@ public class VBAMacroReader implements Closeable {
|
||||||
return new String(buffer, 0, count, charset);
|
return new String(buffer, 0, count, charset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* reads module from input stream and adds it to the modules map for decompression later
|
||||||
|
* on the second pass through this function, the module will be decompressed
|
||||||
|
*
|
||||||
|
* Side-effects: adds a new module to the module map or sets the buf field on the module
|
||||||
|
* to the decompressed stream contents (the VBA code for one module)
|
||||||
|
*
|
||||||
|
* @param in the run-length encoded input stream to read from
|
||||||
|
* @param streamName the stream name of the module
|
||||||
|
* @param modules a map to store the modules
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
private static void readModule(RLEDecompressingInputStream in, String streamName, ModuleMap modules) throws IOException {
|
||||||
|
int moduleOffset = in.readInt();
|
||||||
|
Module module = modules.get(streamName);
|
||||||
|
// First time we've seen the module. Add it to the ModuleMap and decompress it later
|
||||||
|
if (module == null) {
|
||||||
|
module = new Module();
|
||||||
|
module.offset = moduleOffset;
|
||||||
|
modules.put(streamName, module);
|
||||||
|
}
|
||||||
|
// Decompress a previously found module and store the decompressed result into module.buf
|
||||||
|
else {
|
||||||
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
RLEDecompressingInputStream stream = new RLEDecompressingInputStream(new ByteArrayInputStream(
|
||||||
|
module.buf, moduleOffset, module.buf.length - moduleOffset));
|
||||||
|
IOUtils.copy(stream, out);
|
||||||
|
stream.close();
|
||||||
|
out.close();
|
||||||
|
module.buf = out.toByteArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Skips <tt>n</tt> bytes in an input stream, throwing IOException if the
|
* Skips <tt>n</tt> bytes in an input stream, throwing IOException if the
|
||||||
* number of bytes skipped is different than requested.
|
* number of bytes skipped is different than requested.
|
||||||
|
@ -243,21 +276,7 @@ public class VBAMacroReader implements Closeable {
|
||||||
streamName = readString(in, recordLength, modules.charset);
|
streamName = readString(in, recordLength, modules.charset);
|
||||||
break;
|
break;
|
||||||
case MODULEOFFSET:
|
case MODULEOFFSET:
|
||||||
int moduleOffset = in.readInt();
|
readModule(in, streamName, modules);
|
||||||
Module module = modules.get(streamName);
|
|
||||||
if (module != null) {
|
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
||||||
RLEDecompressingInputStream stream = new RLEDecompressingInputStream(new ByteArrayInputStream(
|
|
||||||
module.buf, moduleOffset, module.buf.length - moduleOffset));
|
|
||||||
IOUtils.copy(stream, out);
|
|
||||||
stream.close();
|
|
||||||
out.close();
|
|
||||||
module.buf = out.toByteArray();
|
|
||||||
} else {
|
|
||||||
module = new Module();
|
|
||||||
module.offset = moduleOffset;
|
|
||||||
modules.put(streamName, module);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
trySkip(in, recordLength);
|
trySkip(in, recordLength);
|
||||||
|
|
Loading…
Reference in New Issue