| java.lang.Object java.io.Reader gnu.text.LineBufferedReader
All known Subclasses: gnu.mapping.InPort, gnu.text.LineInputStreamReader,
LineBufferedReader | public class LineBufferedReader extends Reader (Code) | | 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).
author: Per Bothner |
Field Summary | |
final public static int | BUFFER_SIZE Default (initial buffer) size. | public char[] | buffer The input buffer, containing the current line etc. | int | highestPos The high-water mark for pos, at a reset or line start. | protected Reader | in | public int | limit The length of the valid (data-containing) part of the buffer. | protected int | lineNumber The current line number (at position of lineStartPos). | protected int | markPos The position of the mark (assuming
readAheadLinit > 0 ).
(Garbage if
readAheadLimit <= 0 ). | Path | path | public int | pos The current read position, as an index into buffer. | protected int | readAheadLimit If mark has been called, and not invalidated, the read ahead limit.
Zero if mark has not been called, or had been invalidated
(due to either calling reset or excessive reading ahead). | public char | readState |
Method Summary | |
public void | close() | static int | countLines(char[] buffer, int start, int limit) | public int | fill(int len) Called by
read() when it needs its buffer filled.
Read characters into buffer, starting at off, for len.
Can assume that len > 0. | public int | getColumnNumber() Return the current (zero-based) column number. | final public boolean | getConvertCR() True if CR and CRLF should be converted to LF. | public int | getLineNumber() Get the current line number.
The "first" line is number number 0. | public String | getName() | public Path | getPath() | 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. | public void | incrLineNumber(int lineDelta, int lineStartPos) | public void | lineStart(boolean revisited) A hook to allow sub-classes to perform some action at start of line. | public synchronized void | mark(int readAheadLimit) | public boolean | markSupported() | public int | peek() | public int | read() | public int | read(char[] cbuf, int off, int len) | public void | readLine(StringBuffer sbuf, char mode) Read a line. | public String | readLine() | public boolean | ready() | public void | reset() | public void | setBuffer(char[] buffer) Specify a buffer to use for the input buffer. | final public void | setConvertCR(boolean convertCR) | public void | setKeepFullLines(boolean keep) Should we preserve the complete current line?
The default is true, but in some cases there can be a performance
improvement if we don't need to keep a long line when filling the buffer. | public void | setLineNumber(int lineNumber) | public void | setName(Object name) | public void | setPath(Path path) | public int | skip(int n) Skip forwards or backwards a number of characters. | public void | skip() | public void | skipRestOfLine() Skips the rest of the current line, including the line terminator. | final public void | skip_quick() Same as skip(), but assumes previous command was a non-EOF peek(). | public void | unread() | 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'. |
BUFFER_SIZE | final public static int BUFFER_SIZE(Code) | | Default (initial buffer) size.
|
buffer | public char[] buffer(Code) | | The input buffer, containing the current line etc.
|
highestPos | int highestPos(Code) | | The high-water mark for pos, at a reset or line start.
|
limit | public int limit(Code) | | The length of the valid (data-containing) part of the buffer.
|
lineNumber | protected int lineNumber(Code) | | The current line number (at position of lineStartPos).
|
markPos | protected int markPos(Code) | | The position of the mark (assuming
readAheadLinit > 0 ).
(Garbage if
readAheadLimit <= 0 ).
|
pos | public int pos(Code) | | The current read position, as an index into buffer.
|
readAheadLimit | protected int readAheadLimit(Code) | | If mark has been called, and not invalidated, the read ahead limit.
Zero if mark has not been called, or had been invalidated
(due to either calling reset or excessive reading ahead).
|
readState | public char readState(Code) | | |
LineBufferedReader | public LineBufferedReader(Reader in)(Code) | | |
countLines | static int countLines(char[] buffer, int start, int limit)(Code) | | |
fill | public int fill(int len) throws java.io.IOException(Code) | | 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()(Code) | | Return the current (zero-based) column number.
|
getConvertCR | final public boolean getConvertCR()(Code) | | True if CR and CRLF should be converted to LF.
|
getLineNumber | public int getLineNumber()(Code) | | Get the current line number.
The "first" line is number number 0.
|
getReadState | public char getReadState()(Code) | | 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.
|
incrLineNumber | public void incrLineNumber(int lineDelta, int lineStartPos)(Code) | | |
lineStart | public void lineStart(boolean revisited) throws java.io.IOException(Code) | | 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.
Parameters: revisited - true if we have read here before (i.e.we did a reset of unread() to get here) |
mark | public synchronized void mark(int readAheadLimit)(Code) | | |
markSupported | public boolean markSupported()(Code) | | |
readLine | public void readLine(StringBuffer sbuf, char mode) throws IOException(Code) | | 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.
|
setConvertCR | final public void setConvertCR(boolean convertCR)(Code) | | |
setKeepFullLines | public void setKeepFullLines(boolean keep)(Code) | | Should we preserve the complete current line?
The default is true, but in some cases there can be a performance
improvement if we don't need to keep a long line when filling the buffer.
|
setLineNumber | public void setLineNumber(int lineNumber)(Code) | | |
skip | public int skip(int n) throws IOException(Code) | | Skip forwards or backwards a number of characters.
|
skipRestOfLine | public void skipRestOfLine() throws java.io.IOException(Code) | | Skips the rest of the current line, including the line terminator.
|
skip_quick | final public void skip_quick() throws java.io.IOException(Code) | | Same as skip(), but assumes previous command was a non-EOF peek().
|
unread_quick | public void unread_quick()(Code) | | 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'.
|
|
|