java.lang.Object
java.io.InputStream
org.bzdev.io.CounterInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
An input stream with a byte count.
This class provides an implementation of InputStream with
a byte counter giving the current position in the input stream.
One use for this class is for software instrumentation during
development (e.g., to empirically determine buffer sizes).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintvoidclose()longgetCount()Get the current byte count.voidmark(int readlimit) booleanintread()intread(byte[] b) intread(byte[] b, int off, int len) voidreset()Repositions this stream to the position at the time themarkmethod was last called on this input stream.longskip(long n) Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, transferTo
-
Constructor Details
-
CounterInputStream
Constructor.- Parameters:
is- the input stream to count.
-
-
Method Details
-
available
- Overrides:
availablein classInputStream- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-
mark
public void mark(int readlimit) - Overrides:
markin classInputStream
-
markSupported
public boolean markSupported()- Overrides:
markSupportedin classInputStream
-
read
- Specified by:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
reset
Repositions this stream to the position at the time themarkmethod was last called on this input stream.The general contract of
resetis:- If the method
markSupportedreturnstrue, then:- If the method
markhas not been called since the stream was created, or the number of bytes read from the stream sincemarkwas last called is larger than the argument tomarkat that last call, then anIOExceptionwill be thrown. - If such an
IOExceptionis not thrown, then the stream is reset to a state such that all the bytes read since the most recent call tomark(or since the start of the file, ifmarkhas not been called) will be resupplied to subsequent callers of thereadmethod, followed by any bytes that otherwise would have been the next input data as of the time of the call toreset.
- If the method
- If the method
markSupportedreturnsfalse, then:- The call to
resetwill throw anIOException. - If an
IOExceptionis not thrown, then the stream is reset to a fixed state that depends on the particular type of the input stream and how it was created. The bytes that will be supplied to subsequent callers of thereadmethod depend on the particular type of the input stream.
- The call to
- Overrides:
resetin classInputStream- Throws:
IOException- the read limit has been exceeded or if the mark is not supported or set.
- If the method
-
skip
- Overrides:
skipin classInputStream- Throws:
IOException
-
getCount
public long getCount()Get the current byte count. This returns the number of bytes that have been read and skipped.- Returns:
- the number of bytes read so far.
-