Extensions for java.io.Reader

buffered

fun Reader.buffered(
    bufferSize: Int = DEFAULT_BUFFER_SIZE
): BufferedReader

Returns a buffered reader wrapping this Reader, or this Reader itself if it is already buffered.

copyTo

fun Reader.copyTo(
    out: Writer,
    bufferSize: Int = DEFAULT_BUFFER_SIZE
): Long

Copies this reader to the given out writer, returning the number of characters copied.

forEachLine

fun Reader.forEachLine(action: (String) -> Unit)

Iterates through each line of this reader, calls action for each line read and closes the Reader when it's completed.

readLines

fun Reader.readLines(): List<String>

Reads this reader content as a list of lines.

readText

fun Reader.readText(): String

Reads this reader completely as a String.

useLines

fun <T> Reader.useLines(block: (Sequence<String>) -> T): T

Calls the block callback giving it a sequence of all the lines in this file and closes the reader once the processing is complete.