public class BoundedReader
extends java.io.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.
| Modifier and Type | Field and Description |
|---|---|
private int |
charsRead |
private static int |
INVALID |
private int |
markedAt |
private int |
maxCharsFromTargetReader |
private int |
readAheadLimit |
private java.io.Reader |
target |
| Constructor and Description |
|---|
BoundedReader(java.io.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()
|
private static final int INVALID
private final java.io.Reader target
private int charsRead
private int markedAt
private int readAheadLimit
private final int maxCharsFromTargetReader
public BoundedReader(java.io.Reader target,
int maxCharsFromTargetReader)
throws java.io.IOException
target - The target stream that will be usedmaxCharsFromTargetReader - The maximum number of characters that can be read from targetjava.io.IOException - if mark failspublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.Readerjava.io.IOException - If an I/O error occurs while calling the underlying reader's close methodpublic void reset()
throws java.io.IOException
reset in class java.io.Readerjava.io.IOException - If an I/O error occurs while calling the underlying reader's reset methodpublic void mark(int readAheadLimit)
throws java.io.IOException
mark in class java.io.ReaderreadAheadLimit - 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.java.io.IOException - If an I/O error occurs while calling the underlying reader's mark methodpublic int read()
throws java.io.IOException
read in class java.io.Readerjava.io.IOException - If an I/O error occurs while calling the underlying reader's read methodpublic int read(char[] cbuf,
int off,
int len)
throws java.io.IOException
read in class java.io.Readercbuf - The buffer to filloff - The offsetlen - The number of chars to readjava.io.IOException - If an I/O error occurs while calling the underlying reader's read methodCopyright (c) 2002-2016 Apache Software Foundation