KIOSourceBufferedReader

class KIOSourceBufferedReader(source: BufferedSource, bufferSize: Int = DEFAULT_BUFFER_SIZE) : Reader

Multiplatform buffered character reader that mirrors the API of Java's BufferedReader:contentReferenceoaicite:0{index=0}. It reads text from a Source (byte stream) and buffers characters to provide efficient reading of single characters, arrays, and lines:contentReferenceoaicite:1{index=1}. The buffer size may be specified, or a default size (8192) is used, which is large enough for most purposes:contentReferenceoaicite:2{index=2}.

This class uses a kotlinx.io.Source as the underlying input and decodes bytes to characters using UTF-8. It supports marking a position in the input and resetting back to that position, and is intended to behave like java.io.BufferedReader.

Constructors

Link copied to clipboard
constructor(source: BufferedSource, bufferSize: Int = DEFAULT_BUFFER_SIZE)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open override fun close()

Closes the stream and the underlying source, releasing any resources:contentReferenceoaicite:28{index=28}. Once the stream is closed, further read(), ready(), mark(), reset(), or skip() invocations will throw an IOException:contentReferenceoaicite:29{index=29}. Closing a previously closed stream has no effect:contentReferenceoaicite:30{index=30}.

Link copied to clipboard
fun mark(readAheadLimit: Int)

Marks the present position in the stream:contentReferenceoaicite:15{index=15}. Subsequent calls to reset will attempt to reposition the stream to this point:contentReferenceoaicite:16{index=16}. The readAheadLimit argument tells how many characters may be read while still preserving the mark. If more than readAheadLimit chars are read after marking, the mark is invalidated.

Link copied to clipboard

Indicates whether this stream supports the mark operation, which it does:contentReferenceoaicite:23{index=23}.

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

Reads a single character from the stream:contentReferenceoaicite:5{index=5}. Returns the character as an integer (0-65535) or -1 if the end of the stream has been reached:contentReferenceoaicite:6{index=6}.

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

Reads up to len characters into the specified portion of the character array cbuf:contentReferenceoaicite:7{index=7}. It returns the number of characters read, or -1 if the end of the stream has been reached before any characters are read:contentReferenceoaicite:8{index=8}. This method will block until at least one character is available or end-of-stream is detected.

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

Reads a line of text from the stream:contentReferenceoaicite:9{index=9}. 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 line feed:contentReferenceoaicite:10{index=10}. The line-termination characters are not included in the returned string.

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

Tells whether this stream is ready to be read:contentReferenceoaicite:12{index=12}. A buffered reader is ready if the buffer is not empty or if the underlying source has more data available (not at end):contentReferenceoaicite:13{index=13}.

Link copied to clipboard
open override fun reset()

Resets the stream to the most recent mark:contentReferenceoaicite:20{index=20}. After reset, the stream will read input from the point where mark was last called. If the stream has not been marked or if the mark was invalidated due to reading beyond the read-ahead limit, an IOException is thrown:contentReferenceoaicite:21{index=21}.

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

Skips over n characters in the stream:contentReferenceoaicite:25{index=25}. This method may read and discard characters in multiple chunks until the specified number of characters have been skipped or the end of stream is reached. It returns the actual number of characters skipped.

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.