SdkBuffer

A collection of bytes in memory. Moving data from one buffer to another is fast.

Thread Safety Buffer is NOT thread safe and should not be shared between threads without external synchronization.

Constructors

Link copied to clipboard
expect constructor()
actual constructor()

Properties

Link copied to clipboard
expect open override val buffer: SdkBuffer

The underlying buffer for this source

actual open override val buffer: SdkBuffer

The underlying buffer for this source

Link copied to clipboard
expect val size: Long
actual val size: Long

Functions

Link copied to clipboard
expect open 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.

actual open override fun close()
Link copied to clipboard
expect open override fun emit()

Writes all buffered data to the underlying sink. Like flush, but weaker (ensures data is pushed to the underlying sink but not necessarily all the way down the chain like flush does). Call before this sink goes out of scope to ensure any buffered data eventually gets to its final destination

actual open override fun emit()

Writes all buffered data to the underlying sink. Like flush, but weaker (ensures data is pushed to the underlying sink but not necessarily all the way down the chain like flush does). Call before this sink goes out of scope to ensure any buffered data eventually gets to its final destination

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
expect open override 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 open override 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
expect open override fun flush()

Writes all buffered data to the underlying sink and pushes it recursively all the way to its final destination.

actual open override fun flush()

Writes all buffered data to the underlying sink.

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
open override fun inputStream(): InputStream

Get an input stream that reads from this source

Link copied to clipboard
open override fun isOpen(): Boolean
Link copied to clipboard
open override fun outputStream(): OutputStream

Return an output stream that writes to this sink

Link copied to clipboard
expect open override 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 open override 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 open override 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.

expect open override fun read(sink: ByteArray, offset: Int, limit: Int): Int

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

open override fun read(dst: ByteBuffer): Int
actual open fun read(sink: SdkBuffer, limit: Long): Long

actual open override 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 open override 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 open override 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 open override fun readByte(): Byte

Read a single byte from this source and return it

actual open override fun readByte(): Byte

Read a single byte from this source and return it

Link copied to clipboard
expect open override fun readByteArray(): ByteArray

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

expect open override fun readByteArray(byteCount: Long): ByteArray

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

actual open override fun readByteArray(): ByteArray

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

actual open override fun readByteArray(byteCount: Long): ByteArray

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

Link copied to clipboard
expect open override fun readInt(): Int

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

actual open override fun readInt(): Int

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

Link copied to clipboard
expect open override fun readIntLe(): Int

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

actual open override fun readIntLe(): Int

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

Link copied to clipboard
expect open override fun readLong(): Long

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

actual open override fun readLong(): Long

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

Link copied to clipboard
expect open override fun readLongLe(): Long

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

actual open override fun readLongLe(): Long

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

Link copied to clipboard
expect open override fun readShort(): Short

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

actual open override fun readShort(): Short

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

Link copied to clipboard
expect open override fun readShortLe(): Short

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

actual open override fun readShortLe(): Short

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

Link copied to clipboard
expect open override fun readUtf8(): String

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

expect open override fun readUtf8(byteCount: Long): String

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

actual open override fun readUtf8(): String

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

actual open override 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 open override 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 open override 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 open override 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 open override 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 open override fun skip(byteCount: Long)

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

actual open override fun skip(byteCount: Long)

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

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
expect open override fun write(source: SdkBuffer, byteCount: Long)

Removes byteCount bytes from source and appends them to this.

expect open override fun write(source: SdkSource, byteCount: Long)

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

expect open override fun write(source: ByteArray, offset: Int, limit: Int)

Write limit bytes from source starting at offset

open override fun write(src: ByteBuffer): Int

actual open override fun write(source: <Error class: unknown class>, byteCount: Long)
actual open override fun write(source: SdkBuffer, byteCount: Long)

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

actual open override fun write(source: ByteArray, offset: Int, limit: Int)

Write limit bytes from source starting at offset

Link copied to clipboard
expect open override fun writeAll(source: SdkSource): Long

Write all bytes from source to this sink.

actual open override fun writeAll(source: <Error class: unknown class>): Long

Write all bytes from source to this sink.

Link copied to clipboard
expect open override fun writeByte(x: Byte)

Writes byte x to this sink

actual open override fun writeByte(x: Byte)

Writes byte x to this sink

Link copied to clipboard
expect open override fun writeInt(x: Int)

Writes int x as a big-endian bytes to this sink

actual open override fun writeInt(x: Int)

Writes int x as a big-endian bytes to this sink

Link copied to clipboard
expect open override fun writeIntLe(x: Int)

Writes int x as a little-endian bytes to this sink

actual open override fun writeIntLe(x: Int)

Writes int x as a little-endian bytes to this sink

Link copied to clipboard
expect open override fun writeLong(x: Long)

Writes long x as a big-endian bytes to this sink

actual open override fun writeLong(x: Long)

Writes long x as a big-endian bytes to this sink

Link copied to clipboard
expect open override fun writeLongLe(x: Long)

Writes long x as a little-endian bytes to this sink

actual open override fun writeLongLe(x: Long)

Writes long x as a little-endian bytes to this sink

Link copied to clipboard
expect open override fun writeShort(x: Short)

Writes short x as a big-endian bytes to this sink

actual open override fun writeShort(x: Short)

Writes short x as a big-endian bytes to this sink

Link copied to clipboard
expect open override fun writeShortLe(x: Short)

Writes short x as a little-endian bytes to this sink

actual open override fun writeShortLe(x: Short)

Writes short x as a little-endian bytes to this sink

Link copied to clipboard
expect open override fun writeUtf8(string: String, start: Int, endExclusive: Int)

Write string as UTF-8 encoded bytes to this sink starting at start index up to endExclusive index.

actual open override fun writeUtf8(string: String, start: Int, endExclusive: Int)

Write UTF8-bytes of string to this sink starting at start index up to endExclusive index.

Inherited functions

Link copied to clipboard

Returns a new sink that buffers writes to the sink. Writes will be efficiently "batched". Call SdkSink.flush when done to emit all data to the underlying sink.

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.