A LineNumberReader with some extra features:
You can seek backwards to the start of the line preceding the
current position (or the mark, if that has been set).
You can use seek with a negative offset, or unread.
You can also use peek to look at the next character without moving.
The method getColumnNumber gives you the current column.
Provides a method that is called at the start of a line.
This is especially useful for interactive streams (e.g. prompting).
It would be nice if we could inherit from LineNumberReader.
That may be possible in theory, but it is difficult and
expensive (because we don't get access to BufferedReader's buffer).
fill
public int fill(int len)
throws java.io.IOException
Called by read() when it needs its buffer filled.
Read characters into buffer, starting at off, for len.
Can assume that len > 0. Only called if pos>=limit.
Return -1 if EOF, otherwise number of read chars.
This can be usefully overridden by sub-classes.
getColumnNumber
public int getColumnNumber()
Return the current (zero-based) column number.
getConvertCR
public final boolean getConvertCR()
True if CR and CRLF should be converted to LF.
getLineNumber
public int getLineNumber()
Get the current line number.
The "first" line is number number 0.
getName
public String getName()
getReadState
public char getReadState()
Return a character that indicates what we are currently reading.
Returns '\n' if we are not inside read; '\"' if reading a string;
'|' if inside a comment; '(' if inside a list; and
' ' if otherwise inside a read.
lineStart
public void lineStart(boolean revisited)
throws java.io.IOException
A hook to allow sub-classes to perform some action at start of line.
Called just before the first character of the new line is read.
revisited
- true if we have read here before (i.e.
we did a reset of unread() to get here)
mark
public void mark(int readAheadLimit)
markSupported
public boolean markSupported()
peek
public int peek()
throws java.io.IOException
read
public int read()
throws java.io.IOException
read
public int read(char[] cbuf,
int off,
int len)
throws java.io.IOException
readLine
public String readLine()
throws IOException
readLine
public void readLine(StringBuffer sbuf,
char mode)
throws IOException
Read a line.
If mode is 'I' ("ignore") ignore delimiters.
If mode is 'P' ("peek") leave delimiter in input stream.
If mode is 'A' ("append") append delimiter to result.
ready
public boolean ready()
throws java.io.IOException
reset
public void reset()
throws IOException
setBuffer
public void setBuffer(char[] buffer)
throws java.io.IOException
Specify a buffer to use for the input buffer.
setConvertCR
public final void setConvertCR(boolean convertCR)
setLineNumber
public void setLineNumber(int lineNumber)
setName
public void setName(String name)
skip
public void skip()
throws java.io.IOException
skip
public int skip(int n)
throws IOException
Skip forwards or backwards a number of characters.
skip_quick
public final void skip_quick()
throws java.io.IOException
Same as skip(), but assumes previous command was a non-EOF peek().
unread
public void unread()
throws java.io.IOException
unread_quick
public void unread_quick()
Same as unread, but only allowed after non-EOF-returning read().
Also allowed after an intervening peek(), but only if the read()
did not return '\r' or '\n'.