| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package org.tukaani.xz; |
| 6 |
|
| 7 |
import java.io.OutputStream; |
| 8 |
import java.io.IOException; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
class CountingOutputStream extends FinishableOutputStream { |
| 19 |
private final OutputStream out; |
| 20 |
private long size = 0; |
| 21 |
|
| 22 |
public CountingOutputStream(OutputStream out) { |
| 23 |
this.out = out; |
| 24 |
} |
| 25 |
|
| 26 |
@Override |
| 27 |
public void write(int b) throws IOException { |
| 28 |
out.write(b); |
| 29 |
if (size >= 0) |
| 30 |
++size; |
| 31 |
} |
| 32 |
|
| 33 |
@Override |
| 34 |
public void write(byte[] b, int off, int len) throws IOException { |
| 35 |
out.write(b, off, len); |
| 36 |
if (size >= 0) |
| 37 |
size += len; |
| 38 |
} |
| 39 |
|
| 40 |
@Override |
| 41 |
public void flush() throws IOException { |
| 42 |
out.flush(); |
| 43 |
} |
| 44 |
|
| 45 |
@Override |
| 46 |
public void close() throws IOException { |
| 47 |
out.close(); |
| 48 |
} |
| 49 |
|
| 50 |
public long getSize() { |
| 51 |
return size; |
| 52 |
} |
| 53 |
} |