COMPRESS-445 try to get compressed count for all supported methods

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

Branch: refs/heads/master
Commit: 0646aa7d4d0ece484e26e8ab262265cc9263c350
Parents: 22c79b2
Author: Stefan Bodewig <bode...@apache.org>
Authored: Sun Apr 22 18:20:29 2018 +0200
Committer: Stefan Bodewig <bode...@apache.org>
Committed: Sun Apr 22 18:20:29 2018 +0200

----------------------------------------------------------------------
 .../archivers/zip/ZipArchiveInputStream.java    | 25 +++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/0646aa7d/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
 
b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
index 12009b0..f1789f6 100644
--- 
a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
+++ 
b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
@@ -472,12 +472,31 @@ public class ZipArchiveInputStream extends 
ArchiveInputStream implements InputSt
         return read;
     }
 
+    /**
+     * @since 1.17
+     */
     @Override
     public long getCompressedCount() {
-        final long infBytes = inf.getBytesRead();
-        return (infBytes > 0) ? infBytes : current.bytesReadFromStream;
+        if (current.entry.getMethod() == ZipArchiveOutputStream.STORED) {
+            return current.bytesReadFromStream;
+        } else if (current.entry.getMethod() == 
ZipArchiveOutputStream.DEFLATED) {
+            return getBytesInflated();
+        } else if (current.entry.getMethod() == 
ZipMethod.UNSHRINKING.getCode()) {
+            return ((UnshrinkingInputStream) current.in).getCompressedCount();
+        } else if (current.entry.getMethod() == ZipMethod.IMPLODING.getCode()) 
{
+            return ((ExplodingInputStream) current.in).getCompressedCount();
+        } else if (current.entry.getMethod() == 
ZipMethod.ENHANCED_DEFLATED.getCode()) {
+            return ((Deflate64CompressorInputStream) 
current.in).getCompressedCount();
+        } else if (current.entry.getMethod() == ZipMethod.BZIP2.getCode()) {
+            return ((BZip2CompressorInputStream) 
current.in).getCompressedCount();
+        } else {
+            return -1;
+        }
     }
 
+    /**
+     * @since 1.17
+     */
     @Override
     public long getUncompressedCount() {
         return uncompressedCount;
@@ -1096,7 +1115,7 @@ public class ZipArchiveInputStream extends 
ArchiveInputStream implements InputSt
         private long bytesRead;
 
         /**
-         * Number of bytes of entry content read so from the stream.
+         * Number of bytes of entry content read from the stream.
          *
          * <p>This may be more than the actual entry's length as some
          * stuff gets buffered up and needs to be pushed back when the

Reply via email to