LineNumberReader

A buffered character-input stream that keeps track of line numbers. This class defines methods .setLineNumber and .getLineNumber for setting and getting the current line number respectively.

By default, line numbering begins at 0. This number increments at every #lt 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.

Author

Mark Reinhold

Since

1.1

Constructors

Link copied to clipboard
constructor(in: Reader)

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

constructor(in: Reader, sz: Int)

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

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The current line number

Functions

Link copied to clipboard
open override fun close()

Closes the reader and releases any associated resources.

Link copied to clipboard
open override fun mark(readAheadLimit: Int)

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.

Link copied to clipboard

Tells whether this stream supports the mark() operation, which it does.

Link copied to clipboard
open override fun read(): Int

Read a single character. #lt 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.

open override fun read(cbuf: CharArray, off: Int, len: Int): Int

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.

open override fun read(target: CharBuffer): Int

Reads characters into a CharBuffer. This default implementation reads into an array and then puts the characters into the buffer.

Link copied to clipboard
fun readLine(ignoreLF: Boolean, term: BooleanArray?): String?

Reads a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), a carriage return followed immediately by a line feed, or by reaching the end-of-file (EOF).

open override fun readLine(): String?

Read a line of text. #lt 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.

Link copied to clipboard
open override fun ready(): Boolean

Tells whether this stream is ready to be read. A buffered character stream is ready if the buffer is not empty, or if the underlying character stream is ready.

Link copied to clipboard
open override fun reset()

Reset the stream to the most recent mark.

Link copied to clipboard
open override fun skip(n: Long): Long

{@inheritDoc}

Link copied to clipboard
open fun transferTo(out: Writer): Long

Reads all characters from this Reader and writes them to out. Returns the number of characters transferred.