public class SizeLimitReader extends Reader
Reader
wrapper that will read only a definite number of
characters from the underlying stream.Modifier and Type | Field and Description |
---|---|
protected long |
currentPosition
The number of characters that have been read from the
in stream. |
protected Reader |
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 characters to read at most from the
in stream. |
Constructor and Description |
---|
SizeLimitReader(Reader in,
long maxSize)
Create a new
SizeLimitInputStream from another stream given
a size limit. |
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the underlying stream.
|
long |
getBytesLeft()
Get the maximum number of characters left to read before the limit, set
in the constructor, is reached.
|
long |
getBytesRead()
Get the number of characters actually read from this stream.
|
long |
getMaxSize()
Get the number of total characters (including characters already read)
that can be read from this stream (as set in the constructor).
|
void |
mark(int readlimit) |
boolean |
markSupported() |
int |
read() |
int |
read(char[] b) |
int |
read(char[] b,
int off,
int len) |
void |
reset() |
long |
skip(long n) |
protected long currentPosition
protected Reader in
protected long markPosition
protected final long maxSize
in
stream.
Read methods should check to ensure that the number of characters read
never exceeds maxSize.public SizeLimitReader(Reader 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 characters to allow to be read from the
underlying stream.public void close() throws IOException
Close the underlying stream. Calling this method may make data on the underlying stream unavailable.
close
in interface Closeable
close
in interface AutoCloseable
close
in class Reader
IOException
public long getBytesLeft()
public long getBytesRead()
public long getMaxSize()
public void mark(int readlimit) throws IOException
mark
in class Reader
IOException
public boolean markSupported()
markSupported
in class Reader
public int read() throws IOException
read
in class Reader
IOException
public int read(char[] b) throws IOException
read
in class Reader
IOException
public int read(char[] b, int off, int len) throws IOException
read
in class Reader
IOException
public void reset() throws IOException
reset
in class Reader
IOException
public long skip(long n) throws IOException
skip
in class Reader
IOException
Copyright © 2008–2016. All rights reserved.