make ZipFile return statistics for stored entries
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 InputStream getInputStream(final ZipArchiveEntry ze)
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 boolean equals(final Object other) {
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();
+ }
+ }
}
