public class PositionalPushbackReader extends LineNumberReader
Since it is inifinite, it keeps track of the line lengths of all read lines in a humpty-dumpty linked list, so when newlines are pushed back, the column position is maintained. A similarly linked list is used for pushback chars. I am not certain of the need for a hand rolled linked list for this, but the overhead of boxing seems blah.
End-of-line is denoted by newlines only, and only newlines should be pushed back.
It would have been nice to fit this into PegLeg, as it would be much more efficient for parsing.
| Constructor and Description |
|---|
PositionalPushbackReader(Reader r) |
PositionalPushbackReader(String source) |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
int |
getColumnPosition()
Position of last read character in the current line.
|
int |
getLineNumber()
Line number of last read character.
|
void |
mark(int readAheadLimit) |
boolean |
markSupported() |
void |
pushback(int ch)
Pushback a character.
|
int |
read()
Core method.
|
int |
read(char[] cbuf) |
int |
read(char[] cbuf,
int off,
int len) |
int |
read(CharBuffer target) |
String |
readLine() |
boolean |
ready() |
void |
reset() |
void |
setLineNumber(int lineNumber) |
long |
skip(long n) |
linespublic PositionalPushbackReader(String source)
public PositionalPushbackReader(Reader r)
public int read()
throws IOException
read in class LineNumberReaderIOExceptionpublic void pushback(int ch)
ch - char to pushback.public long skip(long n)
throws IOException
skip in class LineNumberReaderIOExceptionpublic boolean ready()
throws IOException
ready in class BufferedReaderIOExceptionpublic void reset()
throws IOException
reset in class LineNumberReaderIOExceptionpublic int read(CharBuffer target) throws IOException
read in interface Readableread in class ReaderIOExceptionpublic int read(char[] cbuf)
throws IOException
read in class ReaderIOExceptionpublic boolean markSupported()
markSupported in class BufferedReaderpublic void mark(int readAheadLimit)
mark in class LineNumberReaderpublic int read(char[] cbuf,
int off,
int len)
throws IOException
read in class LineNumberReaderIOExceptionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class BufferedReaderIOExceptionpublic int getColumnPosition()
public int getLineNumber()
getLineNumber in class LineNumberReaderpublic void setLineNumber(int lineNumber)
setLineNumber in class LineNumberReaderpublic String readLine() throws IOException
readLine in class LineNumberReaderIOExceptionCopyright © 2020. All rights reserved.