public class GuardedInputStream extends MeasuredInputStream
This object is useful when parsing files where specific blocks of a file have a predetermined size: with this object you can guarantee you read only a fixed number of bytes. So if data inside the block is corrupt, or if you want to loosely guard how you read each block, this object will make sure you don't read too far.
The mark() and reset() methods are not supported.
| Constructor and Description |
|---|
GuardedInputStream(InputStream
Constructs a new
GuardedInputStream.
|
| Modifier and Type | Method and Description |
|---|---|
long |
getRemainingLimit()
Returns the number of bytes that are allowed to be read.
|
boolean |
isAtLimit()
Whether any more data can be read from this stream (due to the limit it was constructed with).
|
void |
mark(int readlimit)
|
boolean |
markSupported()
|
int |
read()
|
int |
read(byte[] b)
|
int |
read(byte[] b, int off, int len)
|
void |
reset()
|
long |
skip(long n)
|
available, close, getReadBytes, isCloseable, seek, setCloseablepublic GuardedInputStream(InputStreamin, long limit, boolean canClose)
GuardedInputStream.
in - the underlying
InputStream to use.
limit - the maximum number of bytes that will be read.
canClose - if this is
false, then calling
close will not actually close the underlying stream.
public boolean isAtLimit()
public void mark(int readlimit)
public boolean markSupported()
public int read()
throws IOException
read in class
MeasuredInputStream
IOException
public int read(byte[] b,
int off,
int len)
throws IOException
read in class
MeasuredInputStream
IOException
public long getRemainingLimit()
This number has nothing to do with the number of bytes that are actually remaining in the underlying InputStream. For example, if this GuardedInputStream was designed to read at most 1000 bytes, then this method may return 1000 -- even though there may only be 500 bytes available in the underlying InputStream.
public int read(byte[] b)
throws IOException
read in class
MeasuredInputStream
IOException
public void reset()
throws IOException
reset in class
MeasuredInputStream
IOException
public long skip(long n)
throws IOException
skip in class
MeasuredInputStream
IOException