Author: maxcom
Date: Wed May 18 10:38:08 2011
New Revision: 1124179
URL: http://svn.apache.org/viewvc?rev=1124179&view=rev
Log:
FakeZipEntry: pre-allocate ByteArrayOutputStream when zip entry size is known
to prevent reallocation
Modified:
poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java
Modified:
poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java?rev=1124179&r1=1124178&r2=1124179&view=diff
==============================================================================
---
poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java
(original)
+++
poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java
Wed May 18 10:38:08 2011
@@ -108,7 +108,20 @@ public class ZipInputStreamZipEntrySourc
super(entry.getName());
// Grab the de-compressed contents for later
- ByteArrayOutputStream baos = new
ByteArrayOutputStream();
+ ByteArrayOutputStream baos;
+
+ long entrySize = entry.getSize();
+
+ if (entrySize !=-1) {
+ if (entrySize>=Integer.MAX_VALUE) {
+ throw new IOException("ZIP entry size is too large");
+ }
+
+ baos = new ByteArrayOutputStream((int) entrySize);
+ } else {
+ baos = new ByteArrayOutputStream();
+ }
+
byte[] buffer = new byte[4096];
int read = 0;
while( (read = inp.read(buffer)) != -1 ) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]