]> source.dussan.org Git - poi.git/commitdiff
FakeZipEntry: pre-allocate ByteArrayOutputStream when zip entry size is known to...
authorMaxim Valyanskiy <maxcom@apache.org>
Wed, 18 May 2011 10:38:08 +0000 (10:38 +0000)
committerMaxim Valyanskiy <maxcom@apache.org>
Wed, 18 May 2011 10:38:08 +0000 (10:38 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1124179 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java

index 0b9822eab16cae5afd63c6a90f6c3d471a72e2ad..45674f897e8190af6b06b7fa76e0f3d5e159d28b 100644 (file)
@@ -108,7 +108,20 @@ public class ZipInputStreamZipEntrySource implements ZipEntrySource {
                        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 ) {