|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.io.InputStream
com.gc.iotools.stream.is.SizeLimitInputStream
public class SizeLimitInputStream
An input stream wrapper that will read only a definite number of bytes from the underlying stream.
| Field Summary | |
|---|---|
protected long |
currentPosition
The number of bytes that have been read from the in stream. |
protected InputStream |
in
The underlying stream from which data are read. |
protected long |
markPosition
The position in the stream when mark(int) was called. |
protected long |
maxSize
The number of bytes to read at most from the in stream. |
| Constructor Summary | |
|---|---|
SizeLimitInputStream(InputStream in,
long maxSize)
Create a new SizeLimitInputStream from another stream given
a size limit. |
|
| Method Summary | |
|---|---|
int |
available()
|
void |
close()
Close the underlying stream. |
long |
getBytesLeft()
Get the maximum number of bytes left to read before the limit, set in the constructor, is reached. |
long |
getBytesRead()
Get the number of bytes actually read from this stream. |
long |
getMaxSize()
Get the number of total bytes (including bytes already read) that can be read from this stream (as set in the constructor). |
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)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected InputStream in
protected final long maxSize
in stream. Read
methods should check to ensure that the number of bytes read never
exceeds maxSize.
protected long currentPosition
in stream. Read
methods should check to ensure that currentPosition never exceeds
maxSize.
protected long markPosition
| Constructor Detail |
|---|
public SizeLimitInputStream(InputStream in,
long maxSize)
Create a new SizeLimitInputStream from another stream given
a size limit.
Bytes are read from the underlying stream until size limit is reached.
in - The underlying input stream from where the data is read.maxSize - the max number of bytes to allow to be read from the
underlying stream.| Method Detail |
|---|
public int available()
throws IOException
available in class InputStreamIOException
public void close()
throws IOException
Close the underlying stream. Calling this method may make data on the underlying stream unavailable.
close in interface Closeableclose in class InputStreamIOException - Exception is thrown when some IO error happens in the
underlying stream.public long getBytesLeft()
public long getBytesRead()
public long getMaxSize()
public void mark(int readlimit)
mark in class InputStreampublic boolean markSupported()
markSupported in class InputStream
public int read()
throws IOException
read in class InputStreamIOException
public int read(byte[] b)
throws IOException
read in class InputStreamIOException
public int read(byte[] b,
int off,
int len)
throws IOException
read in class InputStreamIOException
public void reset()
throws IOException
reset in class InputStreamIOException
public long skip(long n)
throws IOException
skip in class InputStreamIOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||