|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.io.Reader | +--java.io.BufferedReader | +--java.io.LineNumberReader
Untamed: A buffered character-input stream that keeps track of line numbers.
This class defines methods void setLineNumber(int)
and
int getLineNumber()
for setting and getting the current
line number respectively.
By default, line numbering begins at 0. This number increments as data is
read, and can be changed with a call to setLineNumber(int)
.
Note however, that setLineNumber(int)
does not actually change the current
position in the stream; it only changes the value that will be returned
by getLineNumber()
.
A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed.
Field Summary | |
private int |
lineNumber
The current line number |
private int |
markedLineNumber
The line number of the mark, if any |
private boolean |
markedSkipLF
The skipLF flag when the mark was set |
private static int |
maxSkipBufferSize
Maximum skip-buffer size |
private char[] |
skipBuffer
Skip buffer, null until allocated |
private boolean |
skipLF
If the next character is a line feed, skip it |
Fields inherited from class java.io.BufferedReader |
|
Fields inherited from class java.io.Reader |
lock |
Constructor Summary | |
LineNumberReader(Reader in)
Enabled: Create a new line-numbering reader, using the default input-buffer size. |
|
LineNumberReader(Reader in,
int sz)
Enabled: Create a new line-numbering reader, reading characters into a buffer of the given size. |
Method Summary | |
int |
getLineNumber()
Enabled: Get the current line number. |
void |
mark(int readAheadLimit)
Enabled: Mark the present position in the stream. |
int |
read()
Enabled: Read a single character. |
int |
read(char[] cbuf,
int off,
int len)
Enabled: Read characters into a portion of an array. |
String |
readLine()
Enabled: Read a line of text. |
void |
reset()
Enabled: Reset the stream to the most recent mark. |
void |
setLineNumber(int lineNumber)
Enabled: Set the current line number. |
long |
skip(long n)
Enabled: Skip characters. |
Methods inherited from class java.io.BufferedReader |
close, getText, getTwine, iterate, iterate, markSupported, readLine, ready |
Methods inherited from class java.io.Reader |
read, readChar, readString |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private int lineNumber
private int markedLineNumber
private boolean skipLF
private boolean markedSkipLF
private static final int maxSkipBufferSize
private char[] skipBuffer
Constructor Detail |
public LineNumberReader(Reader in)
in
- a Reader object to provide the underlying stream.public LineNumberReader(Reader in, int sz)
in
- a Reader object to provide the underlying stream.sz
- an int specifying the size of the buffer.Method Detail |
public void setLineNumber(int lineNumber)
lineNumber
- an int specifying the line number.getLineNumber()
public int getLineNumber()
setLineNumber(int)
public int read() throws IOException
read
in class BufferedReader
IOException
public int read(char[] cbuf, int off, int len) throws IOException
read
in class BufferedReader
cbuf
- Destination bufferoff
- Offset at which to start storing characterslen
- Maximum number of characters to read
IOException
public String readLine() throws IOException
readLine
in class BufferedReader
IOException
public long skip(long n) throws IOException
skip
in class BufferedReader
n
- The number of characters to skip
IOException
public void mark(int readAheadLimit) throws IOException
mark
in class BufferedReader
readAheadLimit
- Limit on the number of characters that may be
read while still preserving the mark. After
reading this many characters, attempting to
reset the stream may fail.
IOException
public void reset() throws IOException
reset
in class BufferedReader
IOException
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |