| 1 | |
package org.jaudiotagger.audio.asf.io; |
| 2 | |
|
| 3 | |
import java.io.IOException; |
| 4 | |
import java.io.OutputStream; |
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | 4 | public class CountingOutputstream extends OutputStream { |
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | 697 | private long count = 0; |
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
private final OutputStream wrapped; |
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
public CountingOutputstream(final OutputStream outputStream) { |
| 34 | 697 | super(); |
| 35 | 697 | assert outputStream != null; |
| 36 | 697 | this.wrapped = outputStream; |
| 37 | 697 | } |
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
@Override |
| 43 | |
public void close() throws IOException { |
| 44 | 0 | this.wrapped.close(); |
| 45 | 0 | } |
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
@Override |
| 51 | |
public void flush() throws IOException { |
| 52 | 0 | this.wrapped.flush(); |
| 53 | 0 | } |
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
public long getCount() { |
| 59 | 216 | return this.count; |
| 60 | |
} |
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
@Override |
| 66 | |
public void write(final byte[] bytes) throws IOException { |
| 67 | 17048 | this.wrapped.write(bytes); |
| 68 | 17048 | this.count += bytes.length; |
| 69 | 17048 | } |
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
@Override |
| 75 | |
public void write(final byte[] bytes, final int off, final int len) |
| 76 | |
throws IOException { |
| 77 | 0 | this.wrapped.write(bytes, off, len); |
| 78 | 0 | this.count += len; |
| 79 | 0 | } |
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
@Override |
| 85 | |
public void write(final int toWrite) throws IOException { |
| 86 | 0 | this.wrapped.write(toWrite); |
| 87 | 0 | this.count++; |
| 88 | 0 | } |
| 89 | |
|
| 90 | |
} |