You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by bo...@apache.org on 2018/04/22 18:10:18 UTC
[3/5] commons-compress git commit: COMPRESS-445 make ZipFile return
statistics for stored entries
COMPRESS-445 make ZipFile return statistics for stored entries
Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/74abd5b7
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/74abd5b7
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/74abd5b7
Branch: refs/heads/master
Commit: 74abd5b73c28bb625d0c74323e64a941c4dc02e7
Parents: b8f7d77
Author: Stefan Bodewig <bo...@apache.org>
Authored: Sun Apr 22 20:08:02 2018 +0200
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Sun Apr 22 20:08:02 2018 +0200
----------------------------------------------------------------------
.../commons/compress/archivers/zip/ZipFile.java | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/74abd5b7/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 5aa8165..868f581 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
@@ -44,7 +44,9 @@ import java.util.zip.ZipException;
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
import org.apache.commons.compress.compressors.deflate64.Deflate64CompressorInputStream;
+import org.apache.commons.compress.utils.CountingInputStream;
import org.apache.commons.compress.utils.IOUtils;
+import org.apache.commons.compress.utils.InputStreamStatistics;
import static org.apache.commons.compress.archivers.zip.ZipConstants.DWORD;
import static org.apache.commons.compress.archivers.zip.ZipConstants.SHORT;
@@ -486,7 +488,7 @@ public class ZipFile implements Closeable {
new BufferedInputStream(createBoundedInputStream(start, ze.getCompressedSize())); //NOSONAR
switch (ZipMethod.getMethodByCode(ze.getMethod())) {
case STORED:
- return is;
+ return new StoredStatisticsStream(is);
case UNSHRINKING:
return new UnshrinkingInputStream(is);
case IMPLODING:
@@ -1256,4 +1258,20 @@ public class ZipFile implements Closeable {
return false;
}
}
+
+ private static class StoredStatisticsStream extends CountingInputStream implements InputStreamStatistics {
+ StoredStatisticsStream(InputStream in) {
+ super(in);
+ }
+
+ @Override
+ public long getCompressedCount() {
+ return super.getBytesRead();
+ }
+
+ @Override
+ public long getUncompressedCount() {
+ return getCompressedCount();
+ }
+ }
}