1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.commons.compress.archivers.zip;
21
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.util.zip.Inflater;
25 import java.util.zip.InflaterInputStream;
26
27 import org.apache.commons.compress.utils.InputStreamStatistics;
28
29
30
31
32
33
34 class InflaterInputStreamWithStatistics extends InflaterInputStream implements InputStreamStatistics {
35
36 private long compressedCount;
37 private long uncompressedCount;
38
39 InflaterInputStreamWithStatistics(final InputStream in) {
40 super(in);
41 }
42
43 InflaterInputStreamWithStatistics(final InputStream in, final Inflater inf) {
44 super(in, inf);
45 }
46
47 InflaterInputStreamWithStatistics(final InputStream in, final Inflater inf, final int size) {
48 super(in, inf, size);
49 }
50
51 @Override
52 protected void fill() throws IOException {
53 super.fill();
54 compressedCount += inf.getRemaining();
55 }
56
57 @Override
58 public long getCompressedCount() {
59 return compressedCount;
60 }
61
62 @Override
63 public long getUncompressedCount() {
64 return uncompressedCount;
65 }
66
67 @Override
68 public int read() throws IOException {
69 final int b = super.read();
70 if (b > -1) {
71 uncompressedCount++;
72 }
73 return b;
74 }
75
76 @Override
77 public int read(final byte[] b, final int off, final int len) throws IOException {
78 final int bytes = super.read(b, off, len);
79 if (bytes > -1) {
80 uncompressedCount += bytes;
81 }
82 return bytes;
83 }
84 }