java.lang.Object
java.io.InputStream
java.io.FilterInputStream
java.io.PushbackInputStream
i2p.susi.util.EOFOnMatchInputStream
- All Implemented Interfaces:
ReadCounter, Closeable, AutoCloseable
InputStream that returns EOF when input matches specified bytes. The reader never sees bytes from a full match. Extends PushbackInputStream for convenience but uses its buffer as a FIFO, not a stack. Do not call unread() methods externally.
Field Summary
Fields inherited from class PushbackInputStream
buf, posFields inherited from class FilterInputStream
inConstructor Summary
ConstructorsConstructorDescriptionEOFOnMatchInputStream(InputStream in, byte[] match) Non-counter mode.EOFOnMatchInputStream(InputStream in, ReadCounter ctr, byte[] match) Counter mode.Method Summary
All MethodsModifier and TypeMethodDescriptionlonggetRead()If constructed with a counter, returns the count (not necessarily starting at 0) minus the buffered/matched count.intread()intread(byte[] buf, int off, int len) Read bytes into a buffer.longskip(long n) Skip bytes in the stream.booleanwasFound()Whether the stream stopped because the search pattern matched.Methods inherited from class PushbackInputStream
available, close, mark, markSupported, reset, transferTo, unread, unread, unreadMethods inherited from class FilterInputStream
readMethods inherited from class InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes
Constructor Details
EOFOnMatchInputStream
Non-counter mode. getRead() will return 0.- Parameters:
in- the underlying stream to read until the match is seenmatch- will be copied
EOFOnMatchInputStream
Counter mode. getRead() will the ReadCounter's value, not including the match bytes.- Parameters:
in- the underlying stream to read until the match is seenctr- counts the bytes read from the underlying stream, or null for non-counter modematch- will be copied
Method Details
getRead
public long getRead()If constructed with a counter, returns the count (not necessarily starting at 0) minus the buffered/matched count. Otherwise returns 0.- Specified by:
getReadin interfaceReadCounter- Returns:
- the number of bytes read from the underlying stream that were not buffered here or matched against the search pattern, or 0 if this stream was not wrapped around a counting stream
wasFound
public boolean wasFound()Whether the stream stopped because the search pattern matched.- Returns:
- true if we returned EOF because we hit the match
read
- Overrides:
readin classPushbackInputStream- Throws:
IOException
read
Read bytes into a buffer.- Overrides:
readin classPushbackInputStream- 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
skip
Skip bytes in the stream.- Overrides:
skipin classPushbackInputStream- Parameters:
n- the number of bytes to skip- Returns:
- the actual number of bytes skipped
- Throws:
IOException- on I/O error