java.lang.Object
java.io.InputStream
java.io.FilterInputStream
i2p.susi.util.CountingInputStream
- All Implemented Interfaces:
ReadCounter, Closeable, AutoCloseable
- Direct Known Subclasses:
LimitInputStream
InputStream that counts bytes read and skipped.
Field Summary
FieldsFields inherited from class FilterInputStream
inConstructor Summary
ConstructorsConstructorDescriptionCreate a CountingInputStream wrapping the given input stream.Method Summary
All MethodsMethods inherited from class FilterInputStream
available, close, mark, markSupported, read, resetMethods inherited from class InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
Field Details
count
protected long countTotal bytes read or skipped.
Constructor Details
CountingInputStream
Create a CountingInputStream wrapping the given input stream.- Parameters:
in- the underlying input stream
Method Details
skip
Skip bytes and count them.- Overrides:
skipin classFilterInputStream- Parameters:
n- number of bytes to skip- Returns:
- actual number of bytes skipped
- Throws:
IOException- on I/O error
getRead
public long getRead()Get the total number of bytes read or skipped so far.- Specified by:
getReadin interfaceReadCounter- Returns:
- total bytes read/skipped
read
Read a single byte and count it.- Overrides:
readin classFilterInputStream- Returns:
- the byte read, or -1 on end of stream
- Throws:
IOException- on I/O error
read
Read bytes into a buffer and count them.- Overrides:
readin classFilterInputStream- Parameters:
buf- the buffer to read intooff- the start offset in the bufferlen- the maximum number of bytes to read- Returns:
- the number of bytes read, or -1 on end of stream
- Throws:
IOException- on I/O error