Class ParserReader
- All Implemented Interfaces:
- Closeable,- AutoCloseable,- Readable,- Positionable
- Direct Known Subclasses:
- UonReader
PushbackReader with a pushback buffer of 1 character.
 Code is optimized to work with a 1 character buffer.
Additionally keeps track of current line and column number, and provides the ability to set mark points and capture characters from the previous mark point.
Notes:
- This class is not thread safe.
See Also:
- 
Field SummaryFields
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidclose()No-op.final ParserReaderdelete()Trims off the last character in the marking buffer.final ParserReaderdelete(int count) Trims off the specified number of last characters in the marking buffer.final StringReturns the contents of the reusable character buffer as a string, and resets the buffer for next usage.final StringgetMarked(int offsetStart, int offsetEnd) Same asgetMarked()except allows you to specify offsets into the buffer.Returns the current position in a reader or input stream.final voidmark()Start buffering the calls to read() so that the text can be gathered from the mark point on callinggetFromMarked().Reads a numeric string from the specified reader.final intpeek()Peeks the next character in the stream.final intSame aspeek()but skips over any whitespace characters.final intread()Reads a single character.intread(char[] cbuf, int off, int len) Subclasses can override this method to provide additional filtering.final Stringread(int num) Read the specified number of characters off the stream.final intSame asread()but detects and combines extended unicode characters (characters above 0x10000).final intSame asread()but skips over any whitespace characters.final ParserReaderreplace(char c) Replace the last read character in the buffer with the specified character.final ParserReaderreplace(int c, int offset) Replaces the last character in the marking buffer with the specified character.unread()Pushes the last read character back into the stream.Methods inherited from class java.io.Readermark, markSupported, nullReader, read, read, ready, reset, skip, transferTo
- 
Field Details- 
rWrapped reader
 
- 
- 
Constructor Details- 
ParserReaderConstructor.- Parameters:
- pipe- The parser input.
- Throws:
- IOException- Thrown by underlying stream.
 
 
- 
- 
Method Details- 
readReads a single character.Note that this method does NOT process extended unicode characters (i.e. characters above 0x10000), but rather returns them as two char s. UsereadCodePoint()to ensure proper handling of extended unicode.- Overrides:
- readin class- Reader
- Returns:
- The character read, or -1 if the end of the stream has been reached.
- Throws:
- IOException- If a problem occurred trying to read from the reader.
 
- 
readSkipWsSame asread()but skips over any whitespace characters.- Returns:
- The first non-whitespace character, or -1 if the end of stream reached.
- Throws:
- IOException- Thrown by underlying stream.
 
- 
readCodePointSame asread()but detects and combines extended unicode characters (characters above 0x10000).- Returns:
- The character read, or -1 if the end of the stream has been reached.
- Throws:
- IOException- If a problem occurred trying to read from the reader.
 
- 
markStart buffering the calls to read() so that the text can be gathered from the mark point on callinggetFromMarked().
- 
peekPeeks the next character in the stream.This is equivalent to doing a read()followed by anunread().- Returns:
- The peeked character, or (char)-1 if the end of the stream has been reached.
- Throws:
- IOException- If a problem occurred trying to read from the reader.
 
- 
peekSkipWsSame aspeek()but skips over any whitespace characters.This is equivalent to doing a read()followed by anunread().- Returns:
- The peeked character, or (char)-1 if the end of the stream has been reached.
- Throws:
- IOException- If a problem occurred trying to read from the reader.
 
- 
readRead the specified number of characters off the stream.- Parameters:
- num- The number of characters to read.
- Returns:
- The characters packaged as a String.
- Throws:
- IOException- If a problem occurred trying to read from the reader.
 
- 
unreadPushes the last read character back into the stream.- Returns:
- This object.
- Throws:
- IOException- If a problem occurred trying to read from the reader.
 
- 
closeNo-op.Input readers are closed in the ParserPipeclass.- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
- Specified by:
- closein class- Reader
- Throws:
- IOException- If a problem occurred trying to read from the reader.
 
- 
getMarkedReturns the contents of the reusable character buffer as a string, and resets the buffer for next usage.- Returns:
- The contents of the reusable character buffer as a string.
 
- 
getMarkedSame asgetMarked()except allows you to specify offsets into the buffer.For example, to return the marked string, but trim the first and last characters, call the following: getFromMarked(1, -1); - Parameters:
- offsetStart- The offset of the start position.
- offsetEnd- The offset of the end position.
- Returns:
- The contents of the reusable character buffer as a string.
 
- 
deleteTrims off the last character in the marking buffer.Useful for removing escape characters from sequences. - Returns:
- This object.
 
- 
deleteTrims off the specified number of last characters in the marking buffer. Useful for removing escape characters from sequences.- Parameters:
- count- The number of characters to delete.
- Returns:
- This object.
 
- 
replaceReplaces the last character in the marking buffer with the specified character.offset must be at least1 for normal characters, and2 for extended unicode characters in order for the replacement to fit into the buffer.- Parameters:
- c- The new character.
- offset- The offset.
- Returns:
- This object.
- Throws:
- IOException- Thrown by underlying stream.
 
- 
replaceReplace the last read character in the buffer with the specified character.- Parameters:
- c- The new character.
- Returns:
- This object.
- Throws:
- IOException- Thrown by underlying stream.
 
- 
parseNumberStringReads a numeric string from the specified reader.- Returns:
- The parsed number string.
- Throws:
- IOException- Thrown by underlying stream.
 
- 
readSubclasses can override this method to provide additional filtering.Default implementation simply calls the same method on the underlying reader. - Specified by:
- readin class- Reader
- Throws:
- IOException
 
- 
getPositionDescription copied from interface:PositionableReturns the current position in a reader or input stream.- Specified by:
- getPositionin interface- Positionable
- Returns:
- The current position in a reader or input stream.
 
 
-