Package-level declarations

Core IO primitives.

Core IO primitives.

Core IO primitives.

Core IO primitives.

Core IO primitives.

Core IO primitives.

Types

Link copied to clipboard
class Buffer : Source, Sink

A collection of bytes in memory.

Link copied to clipboard
annotation class DelicateIoApi

Marks declarations that should be used carefully and in some cases, may cause data corruption or loss.

Link copied to clipboard
expect open class EOFException : IOException

Signals that the end of the file or stream was reached unexpectedly during an input operation.

actual open class EOFException : IOException
actual open class EOFException : IOException
actual open class EOFException : IOException
Link copied to clipboard
annotation class InternalIoApi

Marks declarations that are internal in IO API. These declarations may change or be removed without notice, and not intended for public use. Incorrect of declarations marked as internal may cause data corruption or loss.

Link copied to clipboard
expect open class IOException : Exception

Signals about a general issue occurred during I/O operation.

actual open class IOException : Exception
actual typealias IOException = java.io.IOException
actual open class IOException : Exception
actual open class IOException : Exception
Link copied to clipboard
expect interface RawSink : AutoCloseable

Receives a stream of bytes. RawSink is a base interface for kotlinx-io data receivers.

actual interface RawSink : AutoCloseable
actual interface RawSink : AutoCloseable, Flushable
actual interface RawSink : AutoCloseable
actual interface RawSink : AutoCloseable
Link copied to clipboard

Supplies a stream of bytes. RawSource is a base interface for kotlinx-io data suppliers.

Link copied to clipboard
sealed interface Sink : RawSink

A sink that facilitates typed data writes and keeps a buffer internally so that caller can write some data without sending it directly to an upstream.

Link copied to clipboard
sealed interface Source : RawSource

A source that facilitates typed data reads and keeps a buffer internally so that callers can read chunks of data without requesting it from a downstream on every call.

Functions

Link copied to clipboard

Returns a new ByteChannel instance representing this buffer.

Returns WritableByteChannel backed by this sink. Closing the channel will also close the sink.

Returns ReadableByteChannel backed by this source. Closing the source will close the source.

Link copied to clipboard

Returns an input stream that reads from this source. Closing the stream will also close this source.

Link copied to clipboard
fun Source.asNSInputStream(): NSInputStream

Returns an input stream that reads from this source. Closing the stream will also close this source.

Link copied to clipboard
fun Sink.asNSOutputStream(): NSOutputStream

Returns an output stream that writes to this sink. Closing the stream will also close this sink.

Link copied to clipboard

Returns an output stream that writes to this sink. Closing the stream will also close this sink.

Link copied to clipboard
fun NSOutputStream.asSink(): RawSink

Returns RawSink that writes to an output stream.

Returns RawSink that writes to an output stream.

Link copied to clipboard
fun NSInputStream.asSource(): RawSource

Returns RawSource that reads from an input stream.

Returns RawSource that reads from an input stream.

Link copied to clipboard

Returns a new sink that buffers writes to the sink. The returned sink will batch writes to the sink. Use this wherever you write to a sink to get ergonomic and efficient access to data.

Returns a new source that buffers reads from the source. The returned source will perform bulk reads into its in-memory buffer. Use this wherever you read a source to get ergonomic and efficient access to data.

Link copied to clipboard
fun Buffer.copyTo(out: OutputStream, startIndex: Long = 0, endIndex: Long = size)

Copy bytes from this buffer's subrange, starting at startIndex and ending at endIndex, to out. This method does not consume data from the buffer.

Link copied to clipboard

Returns a sink that discards all data written to it.

Link copied to clipboard
fun Buffer.indexOf(byteString: ByteString, startIndex: Long = 0): Long

fun Source.indexOf(byteString: ByteString, startIndex: Long = 0): Long

Returns the index of the first match for byteString in the source at or after startIndex. This expands the source's buffer as necessary until byteString is found. This reads an unbounded number of bytes into the buffer. Returns -1 if the stream is exhausted before the requested bytes are found.

fun Buffer.indexOf(byte: Byte, startIndex: Long = 0, endIndex: Long = size): Long
fun Source.indexOf(byte: Byte, startIndex: Long = 0, endIndex: Long = Long.MAX_VALUE): Long

Returns an index of byte first occurrence in the range of startIndex to endIndex, or -1 when the range doesn't contain byte.

Link copied to clipboard

Writes up to ByteBuffer.remaining bytes from this buffer to the sink. Return the number of bytes written.

Reads at most ByteBuffer.remaining bytes from this source into sink and returns the number of bytes read.

Link copied to clipboard

Removes all bytes from this source and returns them as a byte array.

Removes byteCount bytes from this source and returns them as a byte array.

Link copied to clipboard

Consumes all bytes from this source and wraps it into a byte string.

Consumes exactly byteCount bytes from this source and wraps it into a byte string.

Link copied to clipboard

Reads a long from this source in signed decimal form (i.e., as a string in base 10 with optional leading -).

Link copied to clipboard

Removes eight bytes from this source and returns a floating point number with type Double composed of it according to the big-endian order.

Link copied to clipboard

Removes eight bytes from this source and returns a floating point number with type Double composed of it according to the little-endian order.

Link copied to clipboard

Removes four bytes from this source and returns a floating point number with type Float composed of it according to the big-endian order.

Link copied to clipboard

Removes four bytes from this source and returns a floating point number with type Float composed of it according to the little-endian order.

Link copied to clipboard

Reads a long form this source in hexadecimal form (i.e., as a string in base 16).

Link copied to clipboard

Removes four bytes from this source and returns an integer composed of it according to the little-endian order.

Link copied to clipboard

Removes and returns UTF-8 encoded characters up to but not including the next line break. A line break is either "\n" or "\r\n"; these characters are not included in the result.

Link copied to clipboard
fun Source.readLineStrict(limit: Long = Long.MAX_VALUE): String

Removes and returns UTF-8 encoded characters up to but not including the next line break, throwing EOFException if a line break was not encountered. A line break is either "\n" or "\r\n"; these characters are not included in the result.

Link copied to clipboard

Removes eight bytes from this source and returns a long integer composed of it according to the little-endian order.

Link copied to clipboard

Removes two bytes from this source and returns a short integer composed of it according to the little-endian order.

Link copied to clipboard

Removes all bytes from this buffer, decodes them as UTF-8, and returns the string.

Removes all bytes from this source, decodes them as UTF-8, and returns the string.

fun Source.readString(byteCount: Long): String

Removes byteCount bytes from this source, decodes them as UTF-8, and returns the string.

Decodes whole content of this stream into a string using charset. Returns empty string if the source is exhausted.

fun Source.readString(byteCount: Long, charset: Charset): String

Decodes byteCount bytes of this stream into a string using charset.

Link copied to clipboard
fun Source.readTo(sink: ByteArray, startIndex: Int = 0, endIndex: Int = sink.size)

Removes exactly endIndex - startIndex bytes from this source and copies them into sink subrange starting at startIndex and ending at endIndex.

fun Buffer.readTo(out: OutputStream, byteCount: Long = size)

Consumes byteCount bytes from this buffer and writes it to out.

Link copied to clipboard

Removes an unsigned byte from this source and returns it.

Link copied to clipboard

Removes four bytes from this source and returns an unsigned integer composed of it according to the big-endian order.

Link copied to clipboard

Removes four bytes from this source and returns an unsigned integer composed of it according to the little-endian order.

Link copied to clipboard

Removes eight bytes from this source and returns an unsigned long integer composed of it according to the big-endian order.

Link copied to clipboard

Removes eight bytes from this source and returns an unsigned long integer composed of it according to the little-endian order.

Link copied to clipboard

Removes two bytes from this source and returns an unsigned short integer composed of it according to the big-endian order.

Link copied to clipboard

Removes two bytes from this source and returns an unsigned short integer composed of it according to the little-endian order.

Link copied to clipboard

Creates a byte string containing a copy of all the data from this buffer.

Link copied to clipboard

Return true if the next byte to be consumed from this source is equal to byte. Otherwise, return false as well as when the source is exhausted.

Link copied to clipboard

Read and exhaust bytes from input into this buffer. Stops reading data on input exhaustion.

Reads all data from source into this buffer.

Link copied to clipboard
fun Sink.write(byteString: ByteString, startIndex: Int = 0, endIndex: Int = byteString.size)

Writes subsequence of data from byteString starting at startIndex and ending at endIndex into a sink.

fun Sink.write(source: ByteBuffer): Int

Writes data from the source into this sink and returns the number of bytes written.

fun Buffer.write(input: InputStream, byteCount: Long): Buffer

Read byteCount bytes from input into this buffer. Throws an exception when input is exhausted before reading byteCount bytes.

Link copied to clipboard

Writes long to this sink in signed decimal form (i.e., as a string in base 10).

Link copied to clipboard
fun Sink.writeDouble(double: Double)

Writes eight bytes of a bit representation of double, in the big-endian order, to this sink. Bit representation of the double corresponds to the IEEE 754 floating-point "double format" bit layout.

Link copied to clipboard

Writes eight bytes of a bit representation of double, in the little-endian order, to this sink. Bit representation of the double corresponds to the IEEE 754 floating-point "double format" bit layout.

Link copied to clipboard
fun Sink.writeFloat(float: Float)

Writes four bytes of a bit representation of float, in the big-endian order, to this sink. Bit representation of the float corresponds to the IEEE 754 floating-point "single format" bit layout.

Link copied to clipboard
fun Sink.writeFloatLe(float: Float)

Writes four bytes of a bit representation of float, in the little-endian order, to this sink. Bit representation of the float corresponds to the IEEE 754 floating-point "single format" bit layout.

Link copied to clipboard

Writes long to this sink in hexadecimal form (i.e., as a string in base 16).

Link copied to clipboard
fun Sink.writeIntLe(int: Int)

Writes four bytes containing int, in the little-endian order, to this sink.

Link copied to clipboard
fun Sink.writeLongLe(long: Long)

Writes eight bytes containing long, in the little-endian order, to this sink.

Link copied to clipboard
fun Sink.writeShortLe(short: Short)

Writes two bytes containing short, in the little-endian order, to this sink.

Link copied to clipboard
fun Sink.writeString(string: String, startIndex: Int = 0, endIndex: Int = string.length)

Encodes the characters at startIndex up to endIndex from string in UTF-8 and writes it to this sink.

fun Sink.writeString(string: String, charset: Charset, startIndex: Int = 0, endIndex: Int = string.length)

Encodes substring of string starting at startIndex and ending at endIndex using charset and writes into this sink.

Link copied to clipboard

Provides direct access to the sink's internal buffer and hints its emit before exit.

Link copied to clipboard
fun Sink.writeUByte(byte: UByte)

Writes am unsigned byte to this sink.

Link copied to clipboard
fun Sink.writeUInt(int: UInt)

Writes four bytes containing int, in the big-endian order, to this sink.

Link copied to clipboard

Writes four bytes containing int, in the little-endian order, to this sink.

Link copied to clipboard
fun Sink.writeULong(long: ULong)

Writes eight bytes containing long, in the big-endian order, to this sink.

Link copied to clipboard

Writes eight bytes containing long, in the little-endian order, to this sink.

Link copied to clipboard
fun Sink.writeUShort(short: UShort)

Writes two bytes containing short, in the big-endian order, to this sink.

Link copied to clipboard

Writes two bytes containing short, in the little-endian order, to this sink.