SdkBufferedSource

expect sealed interface SdkBufferedSource : SdkSource

A source that keeps a buffer internally such that small reads are performant. It also allows peeking ahead, buffering data as necessary, before consuming it.

Inheritors

Inheritors

Properties

Link copied to clipboard
expect abstract val buffer: SdkBuffer

The underlying buffer for this source

actual abstract val buffer: SdkBuffer

The underlying buffer for this source

Functions

Link copied to clipboard
expect abstract fun exhausted(): Boolean

Returns true if there are no more bytes in this source. This will block until there are bytes to read or the source is definitely exhausted.

actual abstract fun exhausted(): Boolean

Returns true if there are no more bytes in this source. This will block until there are bytes to read or the source is definitely exhausted.

Link copied to clipboard
abstract fun inputStream(): InputStream

Get an input stream that reads from this source

Link copied to clipboard
expect abstract fun peek(): SdkBufferedSource

Returns a new SdkBufferedSource that can read data from this source without consuming it. The returned source becomes invalid once this source is next read or closed.

actual abstract fun peek(): SdkBufferedSource

Returns a new SdkBufferedSource that can read data from this source without consuming it. The returned source becomes invalid once this source is next read or closed.

Link copied to clipboard
expect abstract fun read(sink: ByteArray, offset: Int = 0, limit: Int = sink.size - offset): Int

Read up to limit bytes and write them to sink starting at offset

actual abstract fun read(sink: ByteArray, offset: Int, limit: Int): Int

Read up to limit bytes and write them to sink starting at offset

Link copied to clipboard
expect abstract fun readAll(sink: SdkSink): Long

Reads all bytes from this and appends them to sink. Returns the total number of bytes written which will be 0 if this source is exhausted.

actual abstract fun readAll(sink: <Error class: unknown class>): Long

Reads all bytes from this and appends them to sink. Returns the total number of bytes written which will be 0 if this source is exhausted.

Link copied to clipboard
expect abstract fun readByte(): Byte

Read a single byte from this source and return it

actual abstract fun readByte(): Byte

Read a single byte from this source and return it

Link copied to clipboard
expect abstract fun readByteArray(): ByteArray

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

expect abstract fun readByteArray(byteCount: Long): ByteArray

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

actual abstract fun readByteArray(): ByteArray

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

actual abstract fun readByteArray(byteCount: Long): ByteArray

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

Link copied to clipboard
expect abstract fun readInt(): Int

Read four bytes from this source and returns a big-endian int.

actual abstract fun readInt(): Int

Read four bytes in big-endian order from this source and returns them as an int.

Link copied to clipboard
expect abstract fun readIntLe(): Int

Read four bytes from this source and returns a little-endian int.

actual abstract fun readIntLe(): Int

Read four bytes in little-endian order from this source and returns them as an int.

Link copied to clipboard
expect abstract fun readLong(): Long

Read four bytes from this source and returns a big-endian long.

actual abstract fun readLong(): Long

Read eight bytes in big-endian order from this source and returns them as a long.

Link copied to clipboard
expect abstract fun readLongLe(): Long

Read four bytes from this source and returns a little-endian long.

actual abstract fun readLongLe(): Long

Read eight bytes in little-endian order from this source and returns them as a long.

Link copied to clipboard
expect abstract fun readShort(): Short

Read two bytes from this source and returns a big-endian short.

actual abstract fun readShort(): Short

Read two bytes in big-endian order from this source and returns them as a short.

Link copied to clipboard
expect abstract fun readShortLe(): Short

Read two bytes from this source and returns it as a little-endian short.

actual abstract fun readShortLe(): Short

Read two bytes in little-endian order from this source and returns them as a short.

Link copied to clipboard
expect abstract fun readUtf8(): String

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

expect abstract fun readUtf8(byteCount: Long): String

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

actual abstract fun readUtf8(): String

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

actual abstract fun readUtf8(byteCount: Long): String

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

Link copied to clipboard
expect abstract fun request(byteCount: Long): Boolean

Returns true when the buffer contains at least byteCount bytes. False if the source is exhausted before the requested number of bytes could be read

actual abstract fun request(byteCount: Long): Boolean

Returns true when the buffer contains at least byteCount bytes. False if the source is exhausted before the requested number of bytes could be read

Link copied to clipboard
expect abstract fun require(byteCount: Long)

Returns when the buffer contains at least byteCount bytes or throws EOFException if the source is exhausted before the requested number of bytes could be read

actual abstract fun require(byteCount: Long)

Returns when the buffer contains at least byteCount bytes or throws EOFException if the source is exhausted before the requested number of bytes could be read

Link copied to clipboard
expect abstract fun skip(byteCount: Long)

Discards byteCount bytes from this source. Throws IOException if source is exhausted before byteCount bytes can be discarded.

actual abstract fun skip(byteCount: Long)

Discards byteCount bytes from this source. Throws IOException if source is exhausted before byteCount bytes can be discarded.

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
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.

abstract override fun close()
Link copied to clipboard
abstract fun isOpen(): Boolean
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.

abstract fun read(p0: ByteBuffer): Int
Link copied to clipboard
fun SdkSource.readFully(sink: SdkBuffer, byteCount: Long)

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