java.lang.Object
java.io.InputStream
java.io.FilterInputStream
net.i2p.util.LookaheadInputStream
- All Implemented Interfaces:
Closeable, AutoCloseable
Simple lookahead buffer to keep the last K bytes in reserve, configured to easily be reused. Currently only used by the ResettableGZIPInputStream.
Field Summary
Fields inherited from class FilterInputStream
inConstructor Summary
ConstructorsConstructorDescriptionLookaheadInputStream(int lookaheadSize) Configure a stream that hides a number of bytes from the reader.Method Summary
All MethodsModifier and TypeMethodDescriptionbooleanWhether the end of the stream has been reached.byte[]Grab the lookahead footer.voidinitialize(InputStream src) Start the LookaheadInputStream with the given input stream.intread()intread(byte[] buf, int off, int len) longskip(long n) Skip forward, respecting the lookahead buffer.Methods inherited from class FilterInputStream
available, close, mark, markSupported, read, resetMethods inherited from class InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
Constructor Details
LookaheadInputStream
public LookaheadInputStream(int lookaheadSize) Configure a stream that hides a number of bytes from the reader. The last n bytes will never be available from read(), they can only be obtained from getFooter().initialize() MUST be called before doing any read() calls.
- Parameters:
lookaheadSize- how many bytes to hide
Method Details
getEOFReached
public boolean getEOFReached()Whether the end of the stream has been reached.- Returns:
- whether EOF has been reached
initialize
Start the LookaheadInputStream with the given input stream. Resets everything if the LookaheadInputStream was previously used. WARNING - blocking until lookaheadSize bytes are read!- Parameters:
src- the input stream- Throws:
IOException- if less than lookaheadSize bytes could be read.
read
- Overrides:
readin classFilterInputStream- Throws:
IOException
read
- Overrides:
readin classFilterInputStream- Throws:
IOException
skip
Skip forward, respecting the lookahead buffer.- Overrides:
skipin classFilterInputStream- Throws:
IOException