setLineNumber(int) and 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 at the end of the
stream if the last character in the stream is not a line terminator. This
number 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, or any of the previous terminators followed by end of stream, or end of stream not preceded by another terminator.
| Modifier and Type | Field and Description |
|---|---|
| private static final int | |
| private static final int | |
| private static final int | |
| 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 final int | maxSkipBufferSize
Maximum skip-buffer size
|
| private static final int | NONE
Previous character types |
| private int | prevChar
The previous character type |
| private char[] | skipBuffer
Hides java. |
| private boolean | skipLF
If the next character is a line feed, skip it
|
| Access | Constructor and Description |
|---|---|
| public | LineNumberReader(Reader
A Reader object to provide the underlying stream in)Create a new line-numbering reader, using the default input-buffer size. |
| public | LineNumberReader(Reader
A Reader object to provide the underlying stream in, int An int specifying the size of the buffer sz)Create a new line-numbering reader, reading characters into a buffer of the given size. |
| Modifier and Type | Method and Description |
|---|---|
| public int | |
| public void | mark(int
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. readAheadLimit)Overrides java. Mark the present position in the stream. |
| public int | Returns: The character read, or -1 if the end of the stream has been reachedOverrides java. Read a single character. |
| public int | read(char[] cbuf, int off, int len)
Overrides java. Reads characters into a portion of an array. |
| public String | Returns: A String containing the contents of the line, not including any line termination characters, ornull if the end of the stream has been reachedOverrides java. Read a line of text. |
| public void | |
| public void | |
| public long |
| CHAR | back to summary |
|---|---|
| private static final int CHAR | |
| EOF | back to summary |
|---|---|
| private static final int EOF | |
| EOL | back to summary |
|---|---|
| private static final int EOL | |
| lineNumber | back to summary |
|---|---|
| private int lineNumber The current line number | |
| markedLineNumber | back to summary |
|---|---|
| private int markedLineNumber The line number of the mark, if any | |
| markedSkipLF | back to summary |
|---|---|
| private boolean markedSkipLF Hides java. The skipLF flag when the mark was set | |
| maxSkipBufferSize | back to summary |
|---|---|
| private static final int maxSkipBufferSize Hides java. Maximum skip-buffer size | |
| NONE | back to summary |
|---|---|
| private static final int NONE Previous character types | |
| prevChar | back to summary |
|---|---|
| private int prevChar The previous character type | |
| skipBuffer | back to summary |
|---|---|
| private char[] skipBuffer Hides java. Skip buffer, null until allocated | |
| skipLF | back to summary |
|---|---|
| private boolean skipLF Hides java. If the next character is a line feed, skip it | |
| LineNumberReader | back to summary |
|---|---|
| public LineNumberReader(Reader in) Create a new line-numbering reader, using the default input-buffer size.
| |
| LineNumberReader | back to summary |
|---|---|
| public LineNumberReader(Reader in, int sz) Create a new line-numbering reader, reading characters into a buffer of the given size.
| |
| getLineNumber | back to summary |
|---|---|
| public int getLineNumber() Get the current line number.
| |
| mark | back to summary |
|---|---|
| public void mark(int readAheadLimit) throws IOException Overrides java. Mark the present position in the stream. Subsequent calls to reset() will attempt to reposition the stream to this point, and will also reset the line number appropriately.
| |
| read | back to summary |
|---|---|
| public int read() throws IOException Overrides java. Read a single character. Line terminators are compressed into single newline ('\n') characters. The current line number is incremented whenever a line terminator is read, or when the end of the stream is reached and the last character in the stream is not a line terminator.
| |
| read | back to summary |
|---|---|
| public int read(char[] cbuf, int off, int len) throws IOException Overrides java. Reads characters into a portion of an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached. If Line terminators are compressed into single newline ('\n') characters. The current line number is incremented whenever a line terminator is read, or when the end of the stream is reached and the last character in the stream is not a line terminator.
| |
| readLine | back to summary |
|---|---|
| public String readLine() throws IOException Overrides java. Read a line of text. Line terminators are compressed into single newline ('\n') characters. The current line number is incremented whenever a line terminator is read, or when the end of the stream is reached and the last character in the stream is not a line terminator.
| |
| reset | back to summary |
|---|---|
| public void reset() throws IOException Overrides java. Reset the stream to the most recent mark.
| |
| setLineNumber | back to summary |
|---|---|
| public void setLineNumber(int lineNumber) Set the current line number.
| |
| skip | back to summary |
|---|---|
| public long skip(long n) throws IOException Overrides java. Doc from java. Skips characters. This method will block until some characters are available, an I/O error occurs, or the end of the stream is reached. If the stream is already at its end before this method is invoked, then no characters are skipped and zero is returned.
| |