public class BoundedReader extends Reader
One use case is to avoid overrunning the readAheadLimit supplied to java.io.Reader#mark(int), since reading too many characters removes the ability to do a successful reset.
Constructor and Description |
---|
BoundedReader(Reader target,
int maxCharsFromTargetReader)
Constructs a bounded reader
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the target
|
void |
mark(int readAheadLimit)
marks the target stream, @see java.io.Reader#mark(int).
|
int |
read()
Reads a single character, @see java.io.Reader#read()
|
int |
read(char[] cbuf,
int off,
int len)
Reads into an array, @see java.io.Reader#read(char[], int, int)
|
void |
reset()
Resets the target to the latest mark, @see java.io.Reader#reset()
|
public BoundedReader(Reader target, int maxCharsFromTargetReader) throws IOException
target
- The target stream that will be usedmaxCharsFromTargetReader
- The maximum number of characters that can be read from targetIOException
- if mark failspublic void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class Reader
IOException
- If an I/O error occurs while calling the underlying reader's close methodpublic void reset() throws IOException
reset
in class Reader
IOException
- If an I/O error occurs while calling the underlying reader's reset methodpublic void mark(int readAheadLimit) throws IOException
mark
in class Reader
readAheadLimit
- The number of characters that can be read while
still retaining the ability to do #reset().
Note that this parameter is not validated with respect to
maxCharsFromTargetReader. There is no way to pass
past maxCharsFromTargetReader, even if this value is
greater.IOException
- If an I/O error occurs while calling the underlying reader's mark methodpublic int read() throws IOException
read
in class Reader
IOException
- If an I/O error occurs while calling the underlying reader's read methodpublic int read(char[] cbuf, int off, int len) throws IOException
read
in class Reader
cbuf
- The buffer to filloff
- The offsetlen
- The number of chars to readIOException
- If an I/O error occurs while calling the underlying reader's read methodCopyright © 2002–2016 The Apache Software Foundation. All rights reserved.