SdkSource

interface SdkSource : Closeable

A source for reading a stream of bytes (e.g. from file, network, or in-memory buffer). Sources may be layered to transform data as it is read (e.g. to decompress, decrypt, or remove protocol framing).

Most application code should not operate on a source directly, but rather a SdkBufferedSource which is more convenient. Use SdkSource.buffer to wrap any source with a buffer.

Thread/Coroutine Safety

Sources are not thread safe by default. Do not share a source between threads or coroutines without external synchronization.

This is a blocking interface! Use from coroutines should be done from an appropriate dispatcher (e.g. Dispatchers.IO).

Inheritors

Functions

Link copied to clipboard
abstract override fun close()

Closes this source and releases any resources held. It is an error to read from a closed source. This is an idempotent operation.

Link copied to clipboard
abstract fun read(sink: SdkBuffer, limit: Long): Long

Remove at least 1 byte, and up-to limit bytes from this and appends them to sink. Returns the number of bytes read, or -1 if this source is exhausted.

Inherited functions

Link copied to clipboard

Returns a new source that buffers reads from the underlying source. The returned source will perform bulk reads to an in-memory buffer making small reads efficient.

Link copied to clipboard
fun SdkSource.readFully(sink: SdkBuffer, byteCount: Long)

Remove exactly byteCount bytes from this source and appends them to sink.