RawSink

expect interface RawSink : AutoCloseable(source)

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

This interface should be implemented to write data wherever it's needed: to the network, storage, or a buffer in memory. Sinks may be layered to transform received data, such as to compress, encrypt, throttle, or add protocol framing.

Most application code shouldn't operate on a raw sink directly, but rather on a buffered Sink which is both more efficient and more convenient. Use buffered to wrap any raw sink with a buffer.

Implementors should abstain from throwing exceptions other than those that are documented for RawSink methods.

Samples

kotlinx.io.samples.CRC32Sink
import kotlinx.io.*
import kotlin.test.Test
import kotlin.test.assertEquals

fun main() { 
   //sampleStart 
   val crc32Sink = CRC32Sink(discardingSink())

crc32Sink.buffered().use {
    it.writeString("hello crc32")
}

assertEquals(0x9896d398U, crc32Sink.crc32()) 
   //sampleEnd
}

Inheritors

actual interface RawSink : AutoCloseable(source)
actual interface RawSink : AutoCloseable, Flushable(source)
actual interface RawSink : AutoCloseable(source)
actual interface RawSink : AutoCloseable(source)

Functions

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.

Link copied to clipboard
expect abstract override fun close()

Pushes all buffered bytes to their final destination and releases the resources held by this sink. It is an error to write a closed sink. It is safe to close a sink more than once.

actual abstract fun close()
actual abstract override fun close()
actual abstract override fun close()
actual abstract override fun close()
Link copied to clipboard
expect abstract fun flush()

Pushes all buffered bytes to their final destination.

actual abstract fun flush()
actual abstract override fun flush()
actual abstract fun flush()
actual abstract fun flush()
Link copied to clipboard
expect abstract fun write(source: Buffer, byteCount: Long)

Removes byteCount bytes from source and appends them to this sink.

actual abstract fun write(source: Buffer, byteCount: Long)
actual abstract fun write(source: Buffer, byteCount: Long)
actual abstract fun write(source: Buffer, byteCount: Long)
actual abstract fun write(source: Buffer, byteCount: Long)