java.lang.Objectjava.io.Reader
java.io.BufferedReader
java.io.LineNumberReader
public class LineNumberReader
A buffered character-input stream that keeps track of line numbers. This class defines methods
setLineNumber(int)
void setLineNumber(int)
and
getLineNumber()
int getLineNumber()
for setting and getting the current line number respectively.
By default, line numbering begins at 0. This number increments
at every
line terminator
as
the
data is read, and can be changed with a call to
setLineNumber(int)
.
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()
.
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.
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 |
---|
Fields inherited from class java.io. Reader |
---|
lock |
Constructor Summary | |
---|---|
LineNumberReader
(
Reader
in) Create a new line-numbering reader, using the default input-buffer size. |
|
LineNumberReader
(
Reader
in, int sz) Create a new line-numbering reader, reading characters into a buffer of the given size. |
Method Summary | |
---|---|
int |
getLineNumber
() Get the current line number. |
void |
mark
(int readAheadLimit) Mark the present position in the stream. |
int |
read
() Read a single character. |
int |
read
(char[] cbuf, int off, int len) Read characters into a portion of an array. |
String |
readLine
() Read a line of text. |
void |
reset
() Reset the stream to the most recent mark. |
void |
setLineNumber
(int lineNumber) Set the current line number. |
long |
skip
(long n) Skip characters. |
Methods inherited from class java.io. BufferedReader |
---|
close , markSupported , ready |
Methods inherited from class java.io. Reader |
---|
read , read |
Methods inherited from class java.lang. Object |
---|
clone , equals , finalize , getClass , hashCode , notify , notifyAll , toString , wait , wait , wait |
Constructor Detail |
---|
public LineNumberReader(Reader in)
public LineNumberReader(Reader in, int sz)
Method Detail |
---|
public void setLineNumber(int lineNumber)
public int getLineNumber()
public int read() throws IOException
public int read(char[] cbuf, int off, int len) throws IOException
public String readLine() throws IOException
public long skip(long n) throws IOException
public void mark(int readAheadLimit) throws IOException
public void reset() throws IOException