public abstract class LimitedInputStream extends FilterInputStream
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 |
|---|---|
protected long |
limit
Max number of bytes to be read from the wrapped stream
|
in| Modifier | Constructor and Description |
|---|---|
protected |
LimitedInputStream(InputStream in,
long limit)
Create a new LimitedInputStream
|
| Modifier and Type | Method and Description |
|---|---|
int |
available() |
protected abstract void |
limitExceeded()
Called when trying to read past the given
limit and the wrapped
InputStream FilterInputStream.in hasn't yet reached its EOF |
void |
mark(int readLimit) |
int |
read() |
int |
read(byte[] b,
int off,
int len) |
void |
reset() |
long |
skip(long n) |
close, markSupported, readprotected final long limit
protected LimitedInputStream(InputStream in, long limit)
in - an InputStreamlimit - max number of bytes to read from the InputStreampublic int available()
throws IOException
available in class FilterInputStreamIOExceptionpublic void mark(int readLimit)
mark in class FilterInputStreampublic int read()
throws IOException
read in class FilterInputStreamIOExceptionpublic int read(byte[] b,
int off,
int len)
throws IOException
read in class FilterInputStreamIOExceptionpublic void reset()
throws IOException
reset in class FilterInputStreamIOExceptionpublic long skip(long n)
throws IOException
skip in class FilterInputStreamIOExceptionprotected abstract void limitExceeded()
throws IOException
limit and the wrapped
InputStream FilterInputStream.in hasn't yet reached its EOFIOException - subclasses can throw an IOException when the limit is exceeded.
The throws IOException will be forwarded back to the caller of
the read method which read the stream past the limit.Copyright © 2014. All rights reserved.