java.io.InputStream , limiting the number of bytes which can
be read.
This class was copied and modifed from the Google Guava 16.0. Differently
from the original Guava code, when a caller tries to read from this stream
past the given limit and the wrapped stream hasn't yet reached its EOF this
class will call the limitExceeded method instead of returning EOF.
| Modifier and Type | Field and Description |
|---|---|
| private long | |
| protected final long | limit
Max number of bytes to be read from the wrapped stream |
| private long |
| Access | Constructor and Description |
|---|---|
| protected | LimitedInputStream(InputStream
an InputStream in, long max number of bytes to read from the InputStream limit)Create a new LimitedInputStream |
| Modifier and Type | Method and Description |
|---|---|
| public int | available()
Overrides java. Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream. |
| protected abstract void | limitExceeded()
Called when trying to read past the given |
| public synchronized void | mark(int
the maximum limit of bytes that can be read before
the mark position becomes invalid. readLimit)Overrides java. Marks the current position in this input stream. |
| public int | |
| public int | read(byte[]
the buffer into which the data is read. b, int the start offset in array off, int b
at which the data is written.the maximum number of bytes to read. len)Overrides java. Reads up to |
| public synchronized void | reset()
Overrides java. Repositions this stream to the position at the time the
|
| public long | skip(long
the number of bytes to be skipped. n)Overrides java. Skips over and discards |
| left | back to summary |
|---|---|
| private long left | |
| limit | back to summary |
|---|---|
| protected final long limit Max number of bytes to be read from the wrapped stream | |
| mark | back to summary |
|---|---|
| private long mark | |
| LimitedInputStream | back to summary |
|---|---|
| protected LimitedInputStream(InputStream in, long limit) Create a new LimitedInputStream
| |
| available | back to summary |
|---|---|
| public int available() throws IOException Overrides java. Doc from java. Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream. The next caller might be the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes.
| |
| limitExceeded | back to summary |
|---|---|
| protected abstract void limitExceeded() throws IOException Called when trying to read past the given
| |
| mark | back to summary |
|---|---|
| public synchronized void mark(int readLimit) Overrides java. Doc from java. Marks the current position in this input stream. A subsequent
call to the
The
| |
| read | back to summary |
|---|---|
| public int read() throws IOException Overrides java. Doc from java. Reads the next byte of data from the input stream. The value byte is
returned as an
| |
| read | back to summary |
|---|---|
| public int read(byte[] b, int off, int len) throws IOException Overrides java. Doc from java. Reads up to
| |
| reset | back to summary |
|---|---|
| public synchronized void reset() throws IOException Overrides java. Doc from java. Repositions this stream to the position at the time the
Stream marks are intended to be used in situations where you need to read ahead a little to see what's in the stream. Often this is most easily done by invoking some general parser. If the stream is of the type handled by the parse, it just chugs along happily. If the stream is not of that type, the parser should toss an exception when it fails. If this happens within readlimit bytes, it allows the outer code to reset the stream and try another parser.
| |
| skip | back to summary |
|---|---|
| public long skip(long n) throws IOException Overrides java. Doc from java. Skips over and discards
| |