public class BoundedReader extends ReaderA reader that imposes a limit to the number of characters that can be read from an underlying reader, returning EOF when this limit is reached, regardless of state of underlying 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.
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description
close()Closes the target
mark(int readAheadLimit)marks the target stream
read()Reads a single character
read(char cbuf, int off, int len)Reads into an array
reset()Resets the target to the latest mark,
public BoundedReader(Reader target, int maxCharsFromTargetReader)Constructs a bounded reader
target- The target stream that will be used
maxCharsFromTargetReader- The maximum number of characters that can be read from target
public void close() throws IOExceptionCloses the target
public void reset() throws IOExceptionResets the target to the latest mark,
public void mark(int readAheadLimit) throws IOExceptionmarks the target stream
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 method
- See Also:
public int read() throws IOExceptionReads a single character
public int read(char cbuf, int off, int len) throws IOExceptionReads into an array
Copyright © 2002–2021 The Apache Software Foundation. All rights reserved.