# LineNumberReader

public class **LineNumberReader** extends [BufferedReader](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/BufferedReader.html)  
A buffered character-input stream that keeps track of line numbers. This
class defines methods `https://developers.google.com/j2objc/javadoc/jre/reference/java/io/LineNumberReader.html#setLineNumber(int)` and `https://developers.google.com/j2objc/javadoc/jre/reference/java/io/LineNumberReader.html#getLineNumber()` for setting and getting the current line number
respectively.

By default, line numbering begins at 0. This number increments at every
[line terminator](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/LineNumberReader#lt) as the 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.

### Inherited Field Summary

From class [java.io.Reader](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Reader.html)

|---|---|---|
| protected [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [lock](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Reader.html#lock) | The object used to synchronize operations on this stream. |

### Public Constructor Summary

|---|---|
|   | [LineNumberReader](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/LineNumberReader.html#LineNumberReader(java.io.Reader))([Reader](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Reader.html) in) Create a new line-numbering reader, using the default input-buffer size. |
|   | [LineNumberReader](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/LineNumberReader.html#LineNumberReader(java.io.Reader,%20int))([Reader](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Reader.html) in, int sz) Create a new line-numbering reader, reading characters into a buffer of the given size. |

### Public Method Summary

|---|---|
| int | [getLineNumber](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/LineNumberReader.html#getLineNumber())() Get the current line number. |
| void | [mark](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/LineNumberReader.html#mark(int))(int readAheadLimit) Mark the present position in the stream. |
| int | [read](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/LineNumberReader.html#read())() Read a single character. |
| int | [read](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/LineNumberReader.html#read(char[],%20int,%20int))(char\[\] cbuf, int off, int len) Read characters into a portion of an array. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [readLine](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/LineNumberReader.html#readLine())() Read a line of text. |
| void | [reset](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/LineNumberReader.html#reset())() Reset the stream to the most recent mark. |
| void | [setLineNumber](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/LineNumberReader.html#setLineNumber(int))(int lineNumber) Set the current line number. |
| long | [skip](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/LineNumberReader.html#skip(long))(long n) Skip characters. |

### Inherited Method Summary

From class [java.io.BufferedReader](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/BufferedReader.html)

|---|---|
| void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/BufferedReader.html#close())() Closes the stream and releases any system resources associated with it. |
| [Stream](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/stream/Stream.html)\<[String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)\> | [lines](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/BufferedReader.html#lines())() Returns a `Stream`, the elements of which are lines read from this `BufferedReader`. |
| void | [mark](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/BufferedReader.html#mark(int))(int readAheadLimit) Marks the present position in the stream. |
| boolean | [markSupported](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/BufferedReader.html#markSupported())() Tells whether this stream supports the mark() operation, which it does. |
| int | [read](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/BufferedReader.html#read())() Reads a single character. |
| int | [read](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/BufferedReader.html#read(char[],%20int,%20int))(char\[\] cbuf, int off, int len) Reads characters into a portion of an array. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [readLine](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/BufferedReader.html#readLine())() Reads a line of text. |
| boolean | [ready](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/BufferedReader.html#ready())() Tells whether this stream is ready to be read. |
| void | [reset](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/BufferedReader.html#reset())() Resets the stream to the most recent mark. |
| long | [skip](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/BufferedReader.html#skip(long))(long n) Skips characters. |

From class [java.io.Reader](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Reader.html)

|---|---|
| abstract void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Reader.html#close())() Closes the stream and releases any system resources associated with it. |
| void | [mark](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Reader.html#mark(int))(int readAheadLimit) Marks the present position in the stream. |
| boolean | [markSupported](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Reader.html#markSupported())() Tells whether this stream supports the mark() operation. |
| int | [read](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Reader.html#read())() Reads a single character. |
| abstract int | [read](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Reader.html#read(char[],%20int,%20int))(char\[\] cbuf, int off, int len) Reads characters into a portion of an array. |
| int | [read](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Reader.html#read(char[]))(char\[\] cbuf) Reads characters into an array. |
| int | [read](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Reader.html#read(java.nio.CharBuffer))([CharBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/CharBuffer.html) target) Attempts to read characters into the specified character buffer. |
| boolean | [ready](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Reader.html#ready())() Tells whether this stream is ready to be read. |
| void | [reset](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Reader.html#reset())() Resets the stream. |
| long | [skip](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Reader.html#skip(long))(long n) Skips characters. |

From class [java.lang.Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)

|---|---|
| [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [clone](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#clone())() Creates and returns a copy of this `Object`. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj) Compares this instance with the specified object and indicates if they are equal. |
| void | [finalize](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |
| final [Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<?\> | [getClass](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#getClass())() Returns the unique instance of `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html` that represents this object's class. |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#hashCode())() Returns an integer hash code for this object. |
| final void | [notify](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notify())() Causes a thread which is waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| final void | [notifyAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notifyAll())() Causes all threads which are waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#toString())() Returns a string containing a concise, human-readable description of this object. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long,%20int))(long timeout, int nanos) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long))(long timeout) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait())() Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object. |

From interface [java.lang.Readable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Readable.html)

|---|---|
| abstract int | [read](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Readable.html#read(java.nio.CharBuffer))([CharBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/CharBuffer.html) cb) Attempts to read characters into the specified character buffer. |

From interface [java.io.Closeable](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Closeable.html)

|---|---|
| abstract void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Closeable.html#close())() Closes this stream and releases any system resources associated with it. |

From interface [java.lang.AutoCloseable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/AutoCloseable.html)

|---|---|
| abstract void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/AutoCloseable.html#close())() Closes this resource, relinquishing any underlying resources. |

## Public Constructors

#### public
**LineNumberReader**
([Reader](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Reader.html) in)

Create a new line-numbering reader, using the default input-buffer
size.

##### Parameters

| in | A Reader object to provide the underlying stream |
|---|---|

#### public
**LineNumberReader**
([Reader](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Reader.html) in, int sz)

Create a new line-numbering reader, reading characters into a buffer of
the given size.

##### Parameters

| in | A Reader object to provide the underlying stream |
| sz | An int specifying the size of the buffer |
|---|---|

## Public Methods

#### public int
**getLineNumber**
()

Get the current line number.

##### Returns

- The current line number

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/io/LineNumberReader.html#setLineNumber(int)`

#### public void
**mark**
(int readAheadLimit)

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.

##### Parameters

| 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. |
|---|---|

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | If an I/O error occurs |
|---|---|

#### public int
**read**
()

Read a single character. [Line terminators](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/LineNumberReader#lt) are
compressed into single newline ('\\n') characters. Whenever a line
terminator is read the current line number is incremented.

##### Returns

- The character read, or -1 if the end of the stream has been reached

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | If an I/O error occurs |
|---|---|

#### public int
**read**
(char\[\] cbuf, int off, int len)

Read characters into a portion of an array. Whenever a [line terminator](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/LineNumberReader#lt) is read the current line number is
incremented.

##### Parameters

| cbuf | Destination buffer |
| off | Offset at which to start storing characters |
| len | Maximum number of characters to read |
|---|---|

##### Returns

- The number of bytes read, or -1 if the end of the stream has already been reached

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | If an I/O error occurs |
|---|---|

#### public [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)
**readLine**
()

Read a line of text. Whenever a [line terminator](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/LineNumberReader#lt) is
read the current line number is incremented.

##### Returns

- A String containing the contents of the line, not including any [line termination characters](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/LineNumberReader#lt), or null if the end of the stream has been reached

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | If an I/O error occurs |
|---|---|

#### public void
**reset**
()

Reset the stream to the most recent mark.

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | If the stream has not been marked, or if the mark has been invalidated |
|---|---|

#### public void
**setLineNumber**
(int lineNumber)

Set the current line number.

##### Parameters

| lineNumber | An int specifying the line number |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/io/LineNumberReader.html#getLineNumber()`

#### public long
**skip**
(long n)

Skip characters.

##### Parameters

| n | The number of characters to skip |
|---|---|

##### Returns

- The number of characters actually skipped

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | If an I/O error occurs |
| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | If n is negative |
|---|---|