public class BoundedReader extends Reader
One use case is to avoid overrunning the readAheadLimit supplied to 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
|
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(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 methodReader.reset()
public 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 methodReader.mark(int)
public int read() throws IOException
read
in class Reader
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 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 methodReader.read(char[], int, int)
Copyright © 2002–2020 The Apache Software Foundation. All rights reserved.