KReader

abstract class KReader(context: KnioContext, lock: Mutex = Mutex()) : KAutoCloseable

Abstract class for reading character streams. The only methods that a subclass must implement are read(char[], int, int) and close(). Most subclasses, however, will override some of the methods defined here in order to provide higher efficiency, additional functionality, or both.

The coroutine equivalent to the java.io.Reader class.

Inheritors

Constructors

Link copied to clipboard
constructor(context: KnioContext, lock: Mutex = Mutex())

Functions

Link copied to clipboard
suspend fun KReader.buffered(bufferSize: Int? = null): KBufferedReader
Link copied to clipboard
abstract suspend override fun close()

Closes the stream and releases any system resources associated with it. Once the stream has been closed, further read(), ready(), mark(), reset(), or skip() invocations will throw an IOException. Closing a previously closed stream has no effect.

Link copied to clipboard
open suspend fun mark(readLimit: Int)

Marks the present position in the stream. Subsequent calls to reset() will attempt to reposition the stream to this point. Not all character-input streams support the mark() operation.

Link copied to clipboard
open suspend fun markSupported(): Boolean

Tells whether this stream supports the mark() operation. The default implementation always returns false.

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

Reads a single character.

abstract suspend fun read(b: CharBuffer): Int

Attempts to read characters into the specified character buffer. The buffer is used as a repository of characters as-is: the only changes made are the results of a put operation. No flipping or rewinding of the buffer is performed.

open suspend fun read(b: CharArray): Int

Reads characters into an array.

open suspend fun read(b: CharArray, off: Int, len: Int): Int

Reads characters into a portion of an array.

Link copied to clipboard
suspend fun KReader.readText(): String
Link copied to clipboard
open suspend fun ready(): Boolean
Link copied to clipboard
open suspend fun reset()
Link copied to clipboard
open suspend fun skip(n: Long): Long

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.