public class ParserReader extends Reader
As such, a ParserReader can be used whenever the input data needs to be re-read. For example, it is used for pre-parsing a file to determine the nature of its content, before passing it to the appropriate parser for actual parsing.
It can operate in buffering or non-buffering mode. When in buffering mode, it buffers the input, extending the size of the buffer as required.
The ParserReader can be reset to allow re-reading of the input data. When reset and put in non-buffering mode, it consumes the characters in the buffer to service read requests, until it reaches the end of the buffered data, at which point it will start reading from the underlying Reader. When reset and operating in buffering mode, it consumes the characters in the buffer to service read requests, until it reaches the end of the buffered data, at which point it will read more data into the buffer and services read requests from the contents of the buffer.
A ParserReader can only be reset if already in buffering mode.
Constructor and Description |
---|
ParserReader(Reader reader)
Constructs a ParserReader from a Reader.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
boolean |
getBufferingMode()
Gets the buffering mode indicating whether the reader is currently in
buffering mode or non-buffering mode.
|
int |
read()
Reads the next character of data from this reader.
|
int |
read(char[] ch)
Reads up to c.length characters of data from this reader into the
array of characters.
|
int |
read(char[] ch,
int offset,
int len)
Reads up to len characters of data from this reader into an array of
characters at the position specified by offset.
|
void |
resetStream(boolean bufferingMode)
Resets the reader such that it can be re-read.
|
void |
setBufferingMode(boolean mode)
Set the reader into the desired mode.
|
public ParserReader(Reader reader)
reader
- the Readerpublic int read() throws IOException
The character is returned as an int in the range 0 to 16383. If no character is available because the end of the stream has been reached, the value -1 is returned.
read
in class Reader
IOException
- if an I/O error occurspublic int read(char[] ch) throws IOException
read
in class Reader
ch
- the buffer into which the data is readIOException
- if an I/O error occurspublic int read(char[] ch, int offset, int len) throws IOException
read
in class Reader
ch
- the buffer into which the data is readoffset
- the start offset of the datalen
- the maximum number of characters readIOException
- if an I/O error occurspublic void setBufferingMode(boolean mode)
If true is passed in, the reader is put into buffering mode, so that it can be reset subsequently to re-read the data. If false is passed in, the reader is put into non-buffering mode, and it cannot be subsequently reset.
mode
- can be true or false, indicating whether the reader should
be put into buffering mode or non-buffering mode
modepublic boolean getBufferingMode()
public void resetStream(boolean bufferingMode) throws IfsException
bufferingMode
- determines whether the reader should continue
in buffering mode after being reset.IfsException
- if attempting to reset a reader that is not in
buffering modepublic void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class Reader
IOException
Copyright © 2023. All rights reserved.