|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.InputStream
info.sswap.impl.empire.io.ByteLimitInputStream
public class ByteLimitInputStream
A wrapper input stream that will not allow to transfer more than the specified amount of bytes
Field Summary | |
---|---|
private long |
bytesRead
The bytes already read |
private java.io.InputStream |
in
The wrapped input stream. |
private long |
maxBytes
The byte limit |
Constructor Summary | |
---|---|
ByteLimitInputStream(java.io.InputStream in,
long maxBytes)
Creates a new stream wrapping the underlying stream, with the specified byte limit |
Method Summary | |
---|---|
void |
close()
Closes the stream. |
long |
getBytesRead()
Gets the number of bytes already read from the underlying stream. |
long |
getBytesRemaining()
Gets the number of bytes remaining before the limit is reached. |
long |
getMaxBytes()
Gets the byte limit for this stream |
int |
read()
Reads a single byte from the underlying stream. |
int |
read(byte[] b,
int off,
int len)
Reads multiple bytes from the underlying stream |
Methods inherited from class java.io.InputStream |
---|
available, mark, markSupported, read, reset, skip |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private java.io.InputStream in
private long maxBytes
private long bytesRead
Constructor Detail |
---|
public ByteLimitInputStream(java.io.InputStream in, long maxBytes)
in
- the wrapped input streammaxBytes
- the byte limitMethod Detail |
---|
public long getBytesRead()
public long getBytesRemaining()
public long getMaxBytes()
public int read() throws java.io.IOException
read
in class java.io.InputStream
ByteLimitExceededException
- if reading the byte would cause
to go over the byte limit
java.io.IOException
- if the underlying stream reports I/O problempublic int read(byte[] b, int off, int len) throws java.io.IOException
read
in class java.io.InputStream
b
- the byte array where the results will be placedoff
- the offset where the first byte read should be placed in the arraylen
- the requested amount of bytes to read
ByteLimitExceededException
- if the limit has already been reached when invoking this method (if
the limit is reached in the middle of the read, the read will be successfully completed, but will be truncated).
java.io.IOException
- if the underlying stream reports an I/O problempublic void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in class java.io.InputStream
java.io.IOException
- if the underlying stream reports a problem while closing a stream.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |