|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.InputStream
com.evanmclean.evlib.io.BoundedInputStream
public class BoundedInputStream
Input stream wrapper which limits and optionally enforces the number of bytes
read from an input stream. Particularly useful for reading from HTTP
connections which can get out of whack if you don't read all the bytes, or
try and read too many bytes from them. mark(int)
and
reset()
will work if the underlying stream supports it.
Field Summary | |
---|---|
protected InputStream |
in
|
Constructor Summary | |
---|---|
BoundedInputStream(InputStream in,
long max)
Only read a maximum number of characters from the input stream. |
|
BoundedInputStream(InputStream in,
long max,
boolean eat)
Only read a maximum number of characters from the input stream. |
Method Summary | |
---|---|
int |
available()
|
void |
close()
|
long |
eat()
Read and discard any remaining bytes in the input stream, or until we reach the end of the file, whichever comes first. |
long |
getRemaining()
The remaining maximum number of bytes we can read. |
void |
mark(int read_limit)
|
boolean |
markSupported()
|
int |
read()
|
int |
read(byte[] arr,
int off,
int len)
|
void |
reset()
|
long |
skip(long num)
|
Methods inherited from class java.io.InputStream |
---|
read |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final InputStream in
Constructor Detail |
---|
public BoundedInputStream(InputStream in, long max)
Only read a maximum number of characters from the input stream. If
max
is negative then it is effectively unbounded (actually
sets the internal remaining bytes counter to Long.MAX_VALUE).
A call to close()
will call eat()
before closing the
stream to read any remaining bytes.
in
- The input stream to read.max
- The maximum number of bytes to read from the input stream.public BoundedInputStream(InputStream in, long max, boolean eat)
max
is negative then it is effectively unbounded (actually
sets the internal remaining bytes counter to Long.MAX_VALUE).
in
- The input stream to read.max
- The maximum number of bytes to read from the input stream.eat
- If true, an implicit call to eat()
is made on a call to
close()
to read any remaining bytes.Method Detail |
---|
public int available() throws IOException
available
in class InputStream
IOException
public void close() throws IOException
close
in interface Closeable
close
in class InputStream
IOException
public long eat() throws IOException
IOException
public long getRemaining()
public void mark(int read_limit)
mark
in class InputStream
public boolean markSupported()
markSupported
in class InputStream
public int read() throws IOException
read
in class InputStream
IOException
public int read(byte[] arr, int off, int len) throws IOException
read
in class InputStream
IOException
public void reset() throws IOException
reset
in class InputStream
IOException
public long skip(long num) throws IOException
skip
in class InputStream
IOException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |