Package i2p.susi.util
Class EOFOnMatchInputStream
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- java.io.PushbackInputStream
-
- i2p.susi.util.EOFOnMatchInputStream
-
- All Implemented Interfaces:
ReadCounter
,Closeable
,AutoCloseable
public class EOFOnMatchInputStream extends PushbackInputStream implements ReadCounter
A stream that returns EOF when the input matches the bytes provided. The reader will never see any bytes from a full match. We extend PushbackInputStream for convenience, but we use its buffer as a fifo, not a stack. Do not call the unread() methods externally.- Since:
- 0.9.34
-
-
Field Summary
-
Fields inherited from class java.io.PushbackInputStream
buf, pos
-
Fields inherited from class java.io.FilterInputStream
in
-
-
Constructor Summary
Constructors Constructor Description EOFOnMatchInputStream(InputStream in, byte[] match)
Non-counter mode.EOFOnMatchInputStream(InputStream in, ReadCounter ctr, byte[] match)
Counter mode.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
getRead()
If constructed with a counter, returns the count (not necessarily starting at 0) minus the buffered/matched count.int
read()
Debug only.int
read(byte[] buf, int off, int len)
long
skip(long n)
boolean
wasFound()
-
Methods inherited from class java.io.PushbackInputStream
available, close, mark, markSupported, reset, unread, unread, unread
-
Methods inherited from class java.io.FilterInputStream
read
-
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, transferTo
-
-
-
-
Constructor Detail
-
EOFOnMatchInputStream
public EOFOnMatchInputStream(InputStream in, byte[] match)
Non-counter mode. getRead() will return 0.- Parameters:
match
- will be copied
-
EOFOnMatchInputStream
public EOFOnMatchInputStream(InputStream in, ReadCounter ctr, byte[] match)
Counter mode. getRead() will the ReadCounter's value, not including the match bytes.- Parameters:
match
- will be copied
-
-
Method Detail
-
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:
getRead
in interfaceReadCounter
-
wasFound
public boolean wasFound()
- Returns:
- true if we returned EOF because we hit the match
-
read
public int read() throws IOException
Debug only. Return the buffer.- Overrides:
read
in classPushbackInputStream
- Returns:
- the buffer
- Throws:
IOException
-
read
public int read(byte[] buf, int off, int len) throws IOException
- Overrides:
read
in classPushbackInputStream
- Throws:
IOException
-
skip
public long skip(long n) throws IOException
- Overrides:
skip
in classPushbackInputStream
- Throws:
IOException
-
-