COMPRESS-438 buffer bounded streams in ZipFile for better performance

Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/135dd48f
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/135dd48f
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/135dd48f

Branch: refs/heads/master
Commit: 135dd48fda61f81d9b8e0aec0661c1d48226ae3c
Parents: 6ef3fd4
Author: Stefan Bodewig <bode...@apache.org>
Authored: Wed Jan 10 10:09:17 2018 +0100
Committer: Stefan Bodewig <bode...@apache.org>
Committed: Wed Jan 10 10:09:17 2018 +0100

----------------------------------------------------------------------
 src/changes/changes.xml                             |  4 ++++
 .../commons/compress/archivers/zip/ZipFile.java     | 16 ++++++++++------
 2 files changed, 14 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/135dd48f/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index b149482..5c3b44d 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -85,6 +85,10 @@ The <action> type attribute can be add,update,fix,remove.
         Added read-only DEFLATE64 support to ZIP archives and as
         stand-alone CompressorInputStream.
       </action>
+      <action issue="COMPRESS-438" type="add" date="2018-01-10">
+        ZipFile.getInputStream will now always buffer the stream
+        internally in order to improve read performance.
+      </action>
     </release>
     <release version="1.15" date="2017-10-17"
              description="Release 1.15

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/135dd48f/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java 
b/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
index 02ec7dd..f9fe41b 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
@@ -477,21 +477,25 @@ public class ZipFile implements Closeable {
         // cast valididty is checked just above
         ZipUtil.checkRequestedFeatures(ze);
         final long start = ze.getDataOffset();
-        // doesn't get closed if the method is not supported, but doesn't hold 
any resources either
+
+        // doesn't get closed if the method is not supported - which
+        // should never happen because of the checkRequestedFeatures
+        // call above
         final BoundedInputStream bis =
             createBoundedInputStream(start, ze.getCompressedSize()); //NOSONAR
+        final InputStream buf = new BufferedInputStream(bis); //NOSONAR
         switch (ZipMethod.getMethodByCode(ze.getMethod())) {
             case STORED:
                 return bis;
             case UNSHRINKING:
-                return new UnshrinkingInputStream(bis);
+                return new UnshrinkingInputStream(buf);
             case IMPLODING:
                 return new 
ExplodingInputStream(ze.getGeneralPurposeBit().getSlidingDictionarySize(),
-                        
ze.getGeneralPurposeBit().getNumberOfShannonFanoTrees(), new 
BufferedInputStream(bis));
+                        
ze.getGeneralPurposeBit().getNumberOfShannonFanoTrees(), buf);
             case DEFLATED:
                 bis.addDummy();
                 final Inflater inflater = new Inflater(true);
-                return new InflaterInputStream(bis, inflater) {
+                return new InflaterInputStream(buf, inflater) {
                     @Override
                     public void close() throws IOException {
                         try {
@@ -502,9 +506,9 @@ public class ZipFile implements Closeable {
                     }
                 };
             case BZIP2:
-                return new BZip2CompressorInputStream(bis);
+                return new BZip2CompressorInputStream(buf);
             case ENHANCED_DEFLATED:
-                return new Deflate64CompressorInputStream(bis);
+                return new Deflate64CompressorInputStream(buf);
             case AES_ENCRYPTED:
             case EXPANDING_LEVEL_1:
             case EXPANDING_LEVEL_2:

Reply via email to