Package-level declarations

Types

Link copied to clipboard
typealias Buffer = kotlinx.io.Buffer

Represents a buffer with read and write positions.

Link copied to clipboard
Link copied to clipboard
expect enum ByteOrder : Enum<ByteOrder>
actual enum ByteOrder : Enum<ByteOrder>
actual enum ByteOrder : Enum<ByteOrder>
actual enum ByteOrder : Enum<ByteOrder>
actual enum ByteOrder : Enum<ByteOrder>
Link copied to clipboard
typealias BytePacketBuilder = Sink
Link copied to clipboard
typealias ByteReadPacket = Source
Link copied to clipboard
expect interface Closeable
actual interface Closeable
actual typealias Closeable = java.io.Closeable
actual interface Closeable
actual interface Closeable
Link copied to clipboard
typealias Input = Source
Link copied to clipboard
typealias Memory = ByteArray
Link copied to clipboard
typealias Output = Sink

This shouldn't be implemented directly. Inherit Output instead.

Properties

Link copied to clipboard
Link copied to clipboard
val Source.isEmpty: Boolean

For streaming input it should be Input.endOfInput instead.

Link copied to clipboard
val Source.isNotEmpty: Boolean

For streaming input there is no reliable way to detect it without triggering bytes population from the underlying source. Consider using Input.endOfInput or use ByteReadPacket instead.

Link copied to clipboard
val Source.remaining: Long
Link copied to clipboard

Functions

Link copied to clipboard
fun BytePacketBuilder.append(value: CharSequence, startIndex: Int = 0, endIndex: Int = value.length)
Link copied to clipboard
Link copied to clipboard

Build a byte packet in block lambda. Creates a temporary builder and releases it in case of failure

Link copied to clipboard
Link copied to clipboard
fun ByteReadPacket(array: ByteArray, offset: Int = 0, length: Int = array.size): ByteReadPacket
fun ByteReadPacket(byteBuffer: ByteBuffer): Source
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun Source.copyTo(output: Sink): Long

Copy all bytes to the output. Depending on actual input and output implementation it could be zero-copy or copy byte per byte. All regular types such as ByteReadPacket, BytePacketBuilder, Input and Output are always optimized so no bytes will be copied.

Link copied to clipboard
fun ByteReadPacket.discard(count: Long = Long.MAX_VALUE): Long
Link copied to clipboard
fun <T> BytePacketBuilder.preview(function: (ByteReadPacket) -> T): T
fun <T> ByteReadPacket.preview(function: (ByteReadPacket) -> T): T
Link copied to clipboard
Link copied to clipboard
fun Input.readAvailable(buffer: ByteArray, offset: Int = 0, length: Int = buffer.size - offset): Int
Link copied to clipboard
fun Source.readBytes(): ByteArray

Read exactly n bytes (consumes all remaining if n is not specified but up to Int.MAX_VALUE bytes). Does fail if not enough bytes remaining.

fun Buffer.readBytes(count: Int = size.toInt()): ByteArray

Read the specified number of bytes specified (optional, read all remaining by default)

fun Source.readBytes(count: Int): ByteArray
Link copied to clipboard
fun ByteReadPacket.readFully(out: ByteArray, offset: Int = 0, length: Int = out.size - offset)
Link copied to clipboard
fun Source.readText(charset: Charset = Charsets.UTF_8, max: Int = Int.MAX_VALUE): String

Reads at most max characters decoding bytes with specified charset. Extra character bytes will remain unconsumed

Link copied to clipboard
fun Source.readTextExact(charset: Charset = Charsets.UTF_8, n: Int): String

Read exactly n characters interpreting bytes in the specified charset.

Link copied to clipboard
fun Source.readTextExactCharacters(charactersCount: Int, charset: Charset = Charsets.UTF_8): String

Read exactly charactersCount characters interpreting bytes in the specified charset.

Link copied to clipboard
Link copied to clipboard
fun Sink(): Buffer
fun Sink(pool: ObjectPool<*>): Buffer
Link copied to clipboard
fun ByteArray.storeIntAt(index: Int, value: Int)
Link copied to clipboard
fun String(bytes: ByteArray, offset: Int = 0, length: Int = bytes.size, charset: Charset = Charsets.UTF_8): String

Create an instance of String from the specified bytes range starting at offset and bytes length interpreting characters in the specified charset.

Link copied to clipboard
Link copied to clipboard
fun String.toByteArray(charset: Charset = Charsets.UTF_8): ByteArray
Link copied to clipboard
inline fun <T : Closeable?, R> T.use(block: (T) -> R): R
Link copied to clipboard
fun <T> withMemory(size: Int, block: (ByteArray) -> T): T
Link copied to clipboard
fun BytePacketBuilder.write(block: (buffer: CPointer<ByteVar>, offset: Long, length: Long) -> Long): Long
Link copied to clipboard
fun Buffer.writeByteBuffer(source: ByteBuffer)

Write source buffer content moving its position.

Link copied to clipboard
fun BytePacketBuilder.writeFully(buffer: ByteArray, offset: Int = 0, length: Int = buffer.size - offset)
fun BytePacketBuilder.writeFully(buffer: CPointer<ByteVar>, offset: Long, length: Long)
Link copied to clipboard
Link copied to clipboard
fun Sink.writeText(text: CharArray, fromIndex: Int = 0, toIndex: Int = text.size, charset: Charset = Charsets.UTF_8)
fun Sink.writeText(text: CharSequence, fromIndex: Int = 0, toIndex: Int = text.length, charset: Charset = Charsets.UTF_8)

Writes text characters in range \[fromIndex .. toIndex) with the specified charset

Link copied to clipboard