|
Build 1.1_r1 (from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.io.Reader
java.io.BufferedReader
java.io.LineNumberReader
public class LineNumberReader
Wraps an existing Reader and counts the line terminators encountered
while reading the data. The line number starts at 0 and is incremented any
time '\r', '\n' or "\r\n" is read. The class has an
internal buffer for its data. The size of the buffer defaults to 8 KB.
| Field Summary |
|---|
| Fields inherited from class java.io.Reader |
|---|
lock |
| Constructor Summary | |
|---|---|
LineNumberReader(Reader in)
Constructs a new LineNumberReader on the Reader in. |
|
LineNumberReader(Reader in,
int size)
Constructs a new LineNumberReader on the Reader in. |
|
| Method Summary | |
|---|---|
int |
getLineNumber()
Returns the current line number for this reader. |
void |
mark(int readlimit)
Sets a mark position in this reader. |
int |
read()
Reads a single character from the source reader and returns it as an integer with the two higher-order bytes set to 0. |
int |
read(char[] buffer,
int offset,
int count)
Reads at most count characters from the source reader and stores
them in the character array buffer starting at offset. |
String |
readLine()
Returns the next line of text available from this reader. |
void |
reset()
Resets this reader to the last marked location. |
void |
setLineNumber(int lineNumber)
Sets the line number of this reader to the specified lineNumber. |
long |
skip(long count)
Skips count number of characters in this reader. |
| 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)
in. The internal
buffer gets the default size (8 KB).
in - the Reader that is buffered.
public LineNumberReader(Reader in,
int size)
in. The size of
the internal buffer is specified by the parameter size.
in - the Reader that is buffered.size - the size of the buffer to allocate.
IllegalArgumentException - if size <= 0.| Method Detail |
|---|
public int getLineNumber()
public void mark(int readlimit)
throws IOException
readlimit
indicates how many characters can be read before the mark is invalidated.
Sending reset() will reposition this reader back to the marked
position, provided that readlimit has not been surpassed. The
line number associated with this marked position is also stored so that
it can be restored when reset() is called.
mark in class BufferedReaderreadlimit - the number of characters that can be read from this stream
before the mark is invalidated.
IOException - if an error occurs while setting the mark in this reader.BufferedReader.markSupported(),
reset()
public int read()
throws IOException
The line number count is incremented if a line terminator is encountered.
Recognized line terminator sequences are '\r', '\n' and
"\r\n". Line terminator sequences are always translated into
'\n'.
read in class BufferedReaderIOException - if the reader is closed or another IOException occurs.
public int read(char[] buffer,
int offset,
int count)
throws IOException
count characters from the source reader and stores
them in the character array buffer starting at offset.
Returns the number of characters actually read or -1 if no characters
have been read and the end of this reader has been reached.
The line number count is incremented if a line terminator is encountered.
Recognized line terminator sequences are '\r', '\n' and
"\r\n". Line terminator sequences are always translated into
'\n'.
read in class BufferedReaderbuffer - the array in which to store the characters read.offset - the initial position in buffer to store the characters
read from this reader.count - the maximum number of characters to store in buffer.
IOException - if this reader is closed or another IOException occurs.
public String readLine()
throws IOException
'\r',
'\n', "\r\n" or the end of the stream. The returned
string does not include the newline sequence.
readLine in class BufferedReadernull if no characters have
been read before the end of the stream has been reached.
IOException - if this reader is closed or another IOException occurs.
public void reset()
throws IOException
reset in class BufferedReaderIOException - if this reader is already closed, no mark has been set or the
mark is no longer valid because more than readlimit
bytes have been read since setting the mark.mark(int),
BufferedReader.markSupported()public void setLineNumber(int lineNumber)
lineNumber.
Note that this may have side effects on the line number associated with
the last marked position.
lineNumber - the new line number value.mark(int),
reset()
public long skip(long count)
throws IOException
count number of characters in this reader. Subsequent
read()'s will not return these characters unless reset()
is used. This implementation skips count number of characters in
the source reader and increments the line number count whenever line
terminator sequences are skipped.
skip in class BufferedReadercount - the number of characters to skip.
IllegalArgumentException - if count < 0.
IOException - if this reader is closed or another IOException occurs.mark(int),
read(),
reset()
|
Build 1.1_r1 (from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||