commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject [2/2] commons-compress git commit: COMPRESS-441 tweaks by Dawid Weiss
Date Sun, 14 Jan 2018 15:44:29 GMT
COMPRESS-441 tweaks by Dawid Weiss

closes #60


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

Branch: refs/heads/master
Commit: b2fac804f5e867099cd84fe525d52bd77fa4ff19
Parents: 8efea83
Author: Stefan Bodewig <bodewig@apache.org>
Authored: Sun Jan 14 16:43:47 2018 +0100
Committer: Stefan Bodewig <bodewig@apache.org>
Committed: Sun Jan 14 16:43:47 2018 +0100

----------------------------------------------------------------------
 .../compress/archivers/sevenz/Coders.java       |  5 ++++-
 .../commons/compress/archivers/zip/ZipFile.java | 22 +++++++++++---------
 2 files changed, 16 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/b2fac804/src/main/java/org/apache/commons/compress/archivers/sevenz/Coders.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/Coders.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/Coders.java
index 9bd6b28..38b1fd6 100644
--- a/src/main/java/org/apache/commons/compress/archivers/sevenz/Coders.java
+++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/Coders.java
@@ -139,7 +139,10 @@ class Coders {
                 final Coder coder, final byte[] password)
             throws IOException {
             final Inflater inflater = new Inflater(true);
-            // Inflater requires an extra dummy byte, see
+            // Inflater with nowrap=true has this odd contract for a zero padding
+            // byte following the data stream; this used to be zlib's requirement
+            // and has been fixed a long time ago, but the contract persists so
+            // we comply.
             // https://docs.oracle.com/javase/7/docs/api/java/util/zip/Inflater.html#Inflater(boolean)
             final InflaterInputStream inflaterInputStream = new InflaterInputStream(new SequenceInputStream(in,
                 new ByteArrayInputStream(ONE_ZERO_BYTE)), inflater);

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/b2fac804/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 c24d405..a236320 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
@@ -484,22 +484,24 @@ public class ZipFile implements Closeable {
         // 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
+        final InputStream is =
+            new BufferedInputStream(createBoundedInputStream(start, ze.getCompressedSize()));
//NOSONAR
         switch (ZipMethod.getMethodByCode(ze.getMethod())) {
             case STORED:
-                return bis;
+                return is;
             case UNSHRINKING:
-                return new UnshrinkingInputStream(buf);
+                return new UnshrinkingInputStream(is);
             case IMPLODING:
                 return new ExplodingInputStream(ze.getGeneralPurposeBit().getSlidingDictionarySize(),
-                        ze.getGeneralPurposeBit().getNumberOfShannonFanoTrees(), buf);
+                        ze.getGeneralPurposeBit().getNumberOfShannonFanoTrees(), is);
             case DEFLATED:
                 final Inflater inflater = new Inflater(true);
-                // Inflater requires an extra dummy byte, see
+                // Inflater with nowrap=true has this odd contract for a zero padding
+                // byte following the data stream; this used to be zlib's requirement
+                // and has been fixed a long time ago, but the contract persists so
+                // we comply.
                 // https://docs.oracle.com/javase/7/docs/api/java/util/zip/Inflater.html#Inflater(boolean)
-                return new InflaterInputStream(new SequenceInputStream(buf, new ByteArrayInputStream(ONE_ZERO_BYTE)),
+                return new InflaterInputStream(new SequenceInputStream(is, new ByteArrayInputStream(ONE_ZERO_BYTE)),
                     inflater) {
                     @Override
                     public void close() throws IOException {
@@ -511,9 +513,9 @@ public class ZipFile implements Closeable {
                     }
                 };
             case BZIP2:
-                return new BZip2CompressorInputStream(buf);
+                return new BZip2CompressorInputStream(is);
             case ENHANCED_DEFLATED:
-                return new Deflate64CompressorInputStream(buf);
+                return new Deflate64CompressorInputStream(is);
             case AES_ENCRYPTED:
             case EXPANDING_LEVEL_1:
             case EXPANDING_LEVEL_2:


Mime
View raw message