| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package org.tukaani.xz; |
| 6 |
|
| 7 |
import java.io.InputStream; |
| 8 |
import java.io.IOException; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
class CountingInputStream extends CloseIgnoringInputStream { |
| 16 |
private long size = 0; |
| 17 |
|
| 18 |
public CountingInputStream(InputStream in) { |
| 19 |
super(in); |
| 20 |
} |
| 21 |
|
| 22 |
@Override |
| 23 |
public int read() throws IOException { |
| 24 |
int ret = in.read(); |
| 25 |
if (ret != -1 && size >= 0) |
| 26 |
++size; |
| 27 |
|
| 28 |
return ret; |
| 29 |
} |
| 30 |
|
| 31 |
@Override |
| 32 |
public int read(byte[] b, int off, int len) throws IOException { |
| 33 |
int ret = in.read(b, off, len); |
| 34 |
if (ret > 0 && size >= 0) |
| 35 |
size += ret; |
| 36 |
|
| 37 |
return ret; |
| 38 |
} |
| 39 |
|
| 40 |
public long getSize() { |
| 41 |
return size; |
| 42 |
} |
| 43 |
} |