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.
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
|
int |
read()
Reads a single character
|
int |
read(char[] cbuf,
int off,
int len)
Reads into an array
|
void |
reset()
Resets the target to the latest mark,
|
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.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.Reader
java.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.Reader
java.io.IOException
- If an I/O error occurs while calling the underlying reader's reset methodReader.reset()
public void mark(int readAheadLimit) throws java.io.IOException
mark
in class java.io.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.java.io.IOException
- If an I/O error occurs while calling the underlying reader's mark methodReader.mark(int)
public int read() throws java.io.IOException
read
in class java.io.Reader
java.io.IOException
- If an I/O error occurs while calling the underlying reader's read methodReader.read()
public int read(char[] cbuf, int off, int len) throws java.io.IOException
read
in class java.io.Reader
cbuf
- 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 methodReader.read(char[], int, int)
"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"