Package io.ktor.utils.io.core

Types

Link copied to clipboard
abstract class AbstractInput(head: ChunkBuffer, remaining: Long, pool: ObjectPool<ChunkBuffer>) : Input

The default abstract base class implementing Input interface.

Link copied to clipboard
abstract class AbstractOutput : Appendable, Output

The default Output implementation.

Link copied to clipboard
open class Buffer(memory: Memory)

Represents a buffer with read and write positions.

Link copied to clipboard
class BufferLimitExceededException(message: String) : Exception
Link copied to clipboard
expect enum ByteOrder : Enum<ByteOrder>
actual enum ByteOrder : Enum<ByteOrder>
actual enum ByteOrder : Enum<ByteOrder>
Link copied to clipboard
class BytePacketBuilder(headerSizeHint: Int, pool: ObjectPool<ChunkBuffer>) : BytePacketBuilderPlatformBase

A builder that provides ability to build byte packets with no knowledge of it's size. Unlike Java's ByteArrayOutputStream it doesn't copy the whole content every time it's internal buffer overflows but chunks buffers instead. Packet building via build function is O(1) operation and only does instantiate a new ByteReadPacket. Once a byte packet has been built via build function call, the builder could be reused again. You also can discard all written bytes via reset or release. Please note that an instance of builder need to be terminated either via build function invocation or via release call otherwise it will cause byte buffer leak so that may have performance impact.

Link copied to clipboard
abstract class BytePacketBuilderBase : AbstractOutput
Link copied to clipboard
abstract class BytePacketBuilderPlatformBase : BytePacketBuilderBase
Link copied to clipboard
class ByteReadPacket : ByteReadPacketPlatformBase, Input

Read-only immutable byte packet. Could be consumed only once however it does support copy that doesn't copy every byte but creates a new view instead. Once packet created it should be either completely read (consumed) or released via release.

Link copied to clipboard
abstract class ByteReadPacketBase(head: ChunkBuffer, remaining: Long, pool: ObjectPool<ChunkBuffer>) : AbstractInput
Link copied to clipboard
abstract class ByteReadPacketPlatformBase : ByteReadPacketBase
Link copied to clipboard
expect interface Closeable
actual typealias Closeable = Closeable
actual interface Closeable
Link copied to clipboard
expect class EOFException(message: String) : IOException
actual typealias EOFException = EOFException
actual typealias EOFException = EOFException
Link copied to clipboard
annotation class ExperimentalIoApi

API marked with this annotation is experimental and could be changed

Link copied to clipboard
expect interface Input : Closeable

Usually shouldn't be implemented directly. Inherit AbstractInput instead.

actual interface Input : Closeable

Shouldn't be implemented directly. Inherit AbstractInput instead.

actual interface Input : Closeable
Link copied to clipboard
class InsufficientSpaceException(message: String) : Exception
Link copied to clipboard
expect class IoBuffer : ChunkBuffer, Input, Output

A read-write facade to actual buffer of fixed size. Multiple views could share the same actual buffer. Concurrent unsafe. The only concurrent-safe operation is release. In most cases ByteReadPacket and BytePacketBuilder should be used instead.

actual class IoBuffer : ChunkBuffer, Input, Output

A read-write facade to actual buffer of fixed size. Multiple views could share the same actual buffer.

actual class IoBuffer : ChunkBuffer, Input, Output
Link copied to clipboard
expect interface Output : Appendable, Closeable

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

actual interface Output : Closeable, Appendable

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

actual interface Output : Closeable

Functions

Link copied to clipboard
fun Buffer.append(c: Char): Buffer
fun Buffer.append(csq: CharSequence?): Buffer
fun Buffer.append(csq: CharArray, start: Int, end: Int): Buffer
fun Buffer.append(csq: CharSequence?, start: Int, end: Int): Buffer
fun Output.append(csq: CharArray, start: Int = 0, end: Int = csq.size): Appendable
fun Output.append(csq: CharSequence, start: Int = 0, end: Int = csq.length): Appendable
Link copied to clipboard
inline fun buildPacket(headerSizeHint: Int = 0, block: BytePacketBuilder.() -> Unit): ByteReadPacket

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

Link copied to clipboard
expect fun BytePacketBuilder(headerSizeHint: Int = 0): BytePacketBuilder
actual fun BytePacketBuilder(headerSizeHint: Int = 0): BytePacketBuilder
actual fun BytePacketBuilder(headerSizeHint: Int = 0): BytePacketBuilder
Link copied to clipboard
inline fun ByteReadPacket(array: ByteArray, offset: Int = 0, length: Int = array.size): ByteReadPacket
expect fun ByteReadPacket(array: ByteArray, offset: Int = 0, length: Int = array.size, block: (ByteArray) -> Unit): ByteReadPacket
fun ByteReadPacket(bb: ByteBuffer, release: (ByteBuffer) -> Unit = {}): ByteReadPacket
actual inline fun ByteReadPacket(array: ByteArray, offset: Int = 0, length: Int = array.size, crossinline block: (ByteArray) -> Unit): ByteReadPacket
actual fun ByteReadPacket(array: ByteArray, offset: Int = 0, length: Int = array.size, block: (ByteArray) -> Unit): ByteReadPacket
Link copied to clipboard
inline fun Buffer.canRead(): Boolean
Link copied to clipboard
inline fun Buffer.canWrite(): Boolean
Link copied to clipboard
fun ChunkBuffer(ptr: <ERROR CLASS><out <ERROR CLASS>>, lengthInBytes: Int, origin: ChunkBuffer?): ChunkBuffer
fun ChunkBuffer(ptr: <ERROR CLASS><out <ERROR CLASS>>, lengthInBytes: Long, origin: ChunkBuffer?): ChunkBuffer
Link copied to clipboard
fun Input.copyTo(output: Output): 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, AbstractInput and AbstractOutput are always optimized so no bytes will be copied.

Link copied to clipboard
fun Input.discard(): Long

Discard all remaining bytes.

Link copied to clipboard
fun Input.discardExact(n: Int)
fun Input.discardExact(n: Long)

Discard exactly n bytes or fail if not enough bytes in the input to be discarded.

Link copied to clipboard
fun Input.discardUntilDelimiter(delimiter: Byte): Long

Discards bytes until delimiter occurred

Link copied to clipboard
fun Input.discardUntilDelimiters(delimiter1: Byte, delimiter2: Byte): Long

Discards bytes until of of the specified delimiters delimiter1 or delimiter2 occurred

Link copied to clipboard
fun Buffer.fill(times: Int, value: Byte)

Write byte value repeated the specified times.

fun Buffer.fill(times: Int, value: UByte)

Write unsigned byte value repeated the specified times.

fun Buffer.fill(n: Long, v: Byte)

Write byte v value repeated n times.

fun Output.fill(times: Long, value: Byte = 0)
Link copied to clipboard
fun Buffer.flush()
Link copied to clipboard
inline fun Buffer.forEach(block: (Byte) -> Unit)

For every byte from this buffer invokes block function giving it as parameter.

inline fun Input.forEach(block: (Byte) -> Unit)

For every byte from this input invokes block function giving it as parameter.

Link copied to clipboard
fun Buffer.makeView(): Buffer
fun ChunkBuffer.makeView(): ChunkBuffer
Link copied to clipboard
fun Input.peekCharUtf8(): Char
Link copied to clipboard
fun Input.peekTo(destination: Buffer, offset: Int = 0, min: Int = 1, max: Int = Int.MAX_VALUE): Int
fun Input.peekTo(destination: IoBuffer, offset: Int = 0, min: Int = 1, max: Int = Int.MAX_VALUE): Int

Copy at least min but up to max bytes to the specified destination buffer from this input skipping offset bytes. If there are not enough bytes available to provide min bytes then it simply return number of available bytes with no exception so the returned value need to be checked. It is safe to specify max > destination.writeRemaining but min shouldn't be bigger than the destination free space. This function could trigger the underlying source reading that may lead to blocking I/O. It is safe to specify too big offset so in this case this function will always return 0. This function usually copy more bytes than min (unless max = min) but it is not guaranteed. When 0 is returned with offset = 0 then it makes sense to check Input.endOfInput.

Link copied to clipboard
inline fun <R> BytePacketBuilder.preview(block: (tmp: ByteReadPacket) -> R): R

Creates a temporary packet view of the packet being build without discarding any bytes from the builder. This is similar to build().copy() except that the builder keeps already written bytes untouched. A temporary view packet is passed as argument to block function and it shouldn't leak outside of this block otherwise an unexpected behaviour may occur.

Link copied to clipboard
fun Buffer.pushBack(n: Int)

Push back n bytes: only possible if there were at least n bytes read before this operation.

Link copied to clipboard
inline fun Buffer.read(block: (memory: Memory, start: Int, endExclusive: Int) -> Int): Int

Apply block of code with buffer's memory providing read range indices. The returned value of block lambda should return number of bytes to be marked as consumed. No read/write functions on this buffer should be called inside of block otherwise an undefined behaviour may occur including data damage.

Link copied to clipboard
fun Buffer.readAvailable(dst: Buffer, length: Int = dst.writeRemaining): Int

Read at most length available bytes to the dst buffer or -1 if no bytes available for read.

fun Input.readAvailable(dst: Buffer, length: Int = dst.writeRemaining): Int
fun Input.readAvailable(dst: IoBuffer, size: Int = dst.writeRemaining): Int
fun Input.readAvailable(destination: Memory, destinationOffset: Int, length: Int): Int
fun Input.readAvailable(destination: Memory, destinationOffset: Long, length: Long): Long
fun Input.readAvailable(dst: ByteArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailable(dst: DoubleArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailable(dst: FloatArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailable(dst: IntArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailable(dst: LongArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailable(dst: ShortArray, offset: Int = 0, length: Int = dst.size - offset): Int
inline fun IoBuffer.readAvailable(destination: ByteArray, offset: Int = 0, length: Int = destination.size - offset): Int

fun Buffer.readAvailable(destination: ByteArray, offset: Int = 0, length: Int = destination.size - offset): Int
fun Buffer.readAvailable(destination: UByteArray, offset: Int = 0, length: Int = destination.size - offset): Int

Read available for read bytes to the destination array range starting at array offset and length bytes. If less than length bytes available then less bytes will be copied and the corresponding number will be returned as result.

fun Buffer.readAvailable(destination: DoubleArray, offset: Int = 0, length: Int = destination.size - offset): Int
fun Buffer.readAvailable(destination: FloatArray, offset: Int = 0, length: Int = destination.size - offset): Int
fun Buffer.readAvailable(destination: IntArray, offset: Int = 0, length: Int = destination.size - offset): Int
fun Buffer.readAvailable(destination: LongArray, offset: Int = 0, length: Int = destination.size - offset): Int
fun Buffer.readAvailable(destination: ShortArray, offset: Int = 0, length: Int = destination.size - offset): Int
fun Buffer.readAvailable(destination: UIntArray, offset: Int = 0, length: Int = destination.size - offset): Int
fun Buffer.readAvailable(destination: ULongArray, offset: Int = 0, length: Int = destination.size - offset): Int
fun Buffer.readAvailable(destination: UShortArray, offset: Int = 0, length: Int = destination.size - offset): Int

Read available for read bytes to the destination array range starting at array offset and length elements. If less than length elements available then less elements will be copied and the corresponding number will be returned as result (possibly zero).

fun ByteReadPacket.readAvailable(dst: ByteBuffer): Int

Read at most dst.remaining() bytes to the specified dst byte buffer and change its position accordingly

fun Buffer.readAvailable(dst: ByteBuffer, length: Int = dst.remaining()): Int
fun Input.readAvailable(dst: ByteBuffer, length: Int = dst.remaining()): Int
fun ByteReadPacket.readAvailable(dst: <ERROR CLASS><<ERROR CLASS>>, limit: Int): Int
fun ByteReadPacket.readAvailable(dst: <ERROR CLASS><<ERROR CLASS>>, limit: Long): Long

Read at most limit bytes to the specified dst address

fun Buffer.readAvailable(pointer: <ERROR CLASS><<ERROR CLASS>>, offset: Int, length: Int): Int
fun Buffer.readAvailable(pointer: <ERROR CLASS><<ERROR CLASS>>, offset: Long, length: Int): Int
fun Input.readAvailable(dst: <ERROR CLASS><<ERROR CLASS>>, offset: Int, length: Int): Int
fun Input.readAvailable(dst: <ERROR CLASS><<ERROR CLASS>>, offset: Long, length: Long): Long
Link copied to clipboard
fun Buffer.readAvailableLittleEndian(dst: DoubleArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Buffer.readAvailableLittleEndian(dst: FloatArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Buffer.readAvailableLittleEndian(dst: IntArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Buffer.readAvailableLittleEndian(dst: LongArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Buffer.readAvailableLittleEndian(dst: ShortArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Buffer.readAvailableLittleEndian(dst: UIntArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Buffer.readAvailableLittleEndian(dst: ULongArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Buffer.readAvailableLittleEndian(dst: UShortArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailableLittleEndian(dst: DoubleArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailableLittleEndian(dst: FloatArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailableLittleEndian(dst: IntArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailableLittleEndian(dst: LongArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailableLittleEndian(dst: ShortArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailableLittleEndian(dst: UIntArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailableLittleEndian(dst: ULongArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailableLittleEndian(dst: UShortArray, offset: Int = 0, length: Int = dst.size - offset): Int
Link copied to clipboard
@JvmName(name = "readAvailable")
fun Input.readAvailableOld(dst: ByteArray, offset: Int = 0, length: Int = dst.size - offset): Int
@JvmName(name = "readAvailable")
fun Input.readAvailableOld(dst: DoubleArray, offset: Int = 0, length: Int = dst.size - offset): Int
@JvmName(name = "readAvailable")
fun Input.readAvailableOld(dst: FloatArray, offset: Int = 0, length: Int = dst.size - offset): Int
@JvmName(name = "readAvailable")
fun Input.readAvailableOld(dst: IntArray, offset: Int = 0, length: Int = dst.size - offset): Int
@JvmName(name = "readAvailable")
fun Input.readAvailableOld(dst: LongArray, offset: Int = 0, length: Int = dst.size - offset): Int
@JvmName(name = "readAvailable")
fun Input.readAvailableOld(dst: ShortArray, offset: Int = 0, length: Int = dst.size - offset): Int
Link copied to clipboard
fun ByteReadPacket.readByteBuffer(n: Int = remaining.coerceAtMostMaxIntOrFail("Unable to make a ByteBuffer: packet is too big"), direct: Boolean = false): ByteBuffer

Read exactly n (optional, read all remaining by default) bytes to a newly allocated byte buffer

Link copied to clipboard
fun Input.readBytes(): ByteArray

Reads all remaining bytes from the input

fun Buffer.readBytes(count: Int = readRemaining): ByteArray

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

fun ByteReadPacket.readBytes(n: Int = remaining.coerceAtMostMaxIntOrFail("Unable to convert to a ByteArray: packet is too big")): 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 Input.readBytes(n: Int): ByteArray

Reads exactly n bytes from the input or fails if not enough bytes available.

Link copied to clipboard
fun Input.readBytesOf(min: Int = 0, max: Int = Int.MAX_VALUE): ByteArray

Reads at least min but no more than max bytes from the input to a new byte array

Link copied to clipboard
inline fun Buffer.readDirect(block: (ByteBuffer) -> Unit): Int
inline fun AbstractInput.readDirect(size: Int, block: (ByteBuffer) -> Unit)
inline fun ByteReadPacket.readDirect(size: Int, block: (ByteBuffer) -> Unit)
inline fun ByteReadPacketBase.readDirect(size: Int, block: (ByteBuffer) -> Unit)
inline fun Buffer.readDirect(block: (<ERROR CLASS><<ERROR CLASS>>) -> Int): Int
Link copied to clipboard
fun Buffer.readDouble(): Double

Read a floating point number or fail if not enough bytes available for reading. The numeric value is decoded in the network order (Big Endian).

fun Input.readDouble(): Double
inline fun IoBuffer.readDouble(): Double
fun Input.readDouble(byteOrder: ByteOrder): Double
Link copied to clipboard
fun Input.readDoubleFallback(): Double
Link copied to clipboard
fun Buffer.readDoubleLittleEndian(): Double
fun Input.readDoubleLittleEndian(): Double
Link copied to clipboard
fun Buffer.readFloat(): Float

Read a floating point number or fail if not enough bytes available for reading. The numeric value is decoded in the network order (Big Endian).

fun Input.readFloat(): Float
inline fun IoBuffer.readFloat(): Float
fun Input.readFloat(byteOrder: ByteOrder): Float
Link copied to clipboard
fun Input.readFloatFallback(): Float
Link copied to clipboard
fun Buffer.readFloatLittleEndian(): Float
fun Input.readFloatLittleEndian(): Float
Link copied to clipboard
fun Buffer.readFully(dst: Buffer, length: Int = dst.writeRemaining): Int

Read at most length bytes from this buffer to the dst buffer.

fun Input.readFully(dst: Buffer, length: Int = dst.writeRemaining)
fun Input.readFully(dst: IoBuffer, size: Int = dst.writeRemaining)
fun Buffer.readFully(dst: Array<Byte>, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFully(destination: Memory, destinationOffset: Int, length: Int)
fun Input.readFully(destination: Memory, destinationOffset: Long, length: Long)
fun Input.readFully(dst: ByteArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFully(dst: DoubleArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFully(dst: FloatArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFully(dst: IntArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFully(dst: LongArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFully(dst: ShortArray, offset: Int = 0, length: Int = dst.size - offset)
inline fun Input.readFully(dst: UByteArray, offset: Int = 0, length: Int = dst.size - offset)
inline fun Input.readFully(dst: UIntArray, offset: Int = 0, length: Int = dst.size - offset)
inline fun Input.readFully(dst: ULongArray, offset: Int = 0, length: Int = dst.size - offset)
inline fun Input.readFully(dst: UShortArray, offset: Int = 0, length: Int = dst.size - offset)
inline fun IoBuffer.readFully(destination: ByteArray, offset: Int = 0, length: Int = destination.size - offset)

fun Buffer.readFully(destination: ByteArray, offset: Int = 0, length: Int = destination.size - offset)
fun Buffer.readFully(destination: UByteArray, offset: Int = 0, length: Int = destination.size - offset)

Read from this buffer to the destination array to offset and length bytes.

fun Buffer.readFully(destination: DoubleArray, offset: Int = 0, length: Int = destination.size - offset)
fun Buffer.readFully(destination: FloatArray, offset: Int = 0, length: Int = destination.size - offset)
fun Buffer.readFully(destination: IntArray, offset: Int = 0, length: Int = destination.size - offset)
fun Buffer.readFully(destination: LongArray, offset: Int = 0, length: Int = destination.size - offset)
fun Buffer.readFully(destination: ShortArray, offset: Int = 0, length: Int = destination.size - offset)
fun Buffer.readFully(destination: UIntArray, offset: Int = 0, length: Int = destination.size - offset)
fun Buffer.readFully(destination: ULongArray, offset: Int = 0, length: Int = destination.size - offset)
fun Buffer.readFully(destination: UShortArray, offset: Int = 0, length: Int = destination.size - offset)

Read from this buffer to the destination array to offset and length bytes. Numeric values are interpreted in the network byte order (Big Endian).

fun Buffer.readFully(destination: ByteBuffer)

Read buffer's content to the destination buffer moving its position.

fun ByteReadPacket.readFully(dst: ByteBuffer): Int

Read exactly dst.remaining() bytes to the specified dst byte buffer and change its position accordingly

fun Buffer.readFully(dst: ByteBuffer, length: Int)
fun Input.readFully(dst: ByteBuffer, length: Int = dst.remaining())
fun ByteReadPacket.readFully(dst: <ERROR CLASS><<ERROR CLASS>>, size: Int): Int
fun ByteReadPacket.readFully(dst: <ERROR CLASS><<ERROR CLASS>>, size: Long): Long

Read exactly size bytes to the specified dst address

fun Buffer.readFully(pointer: <ERROR CLASS><<ERROR CLASS>>, offset: Int, length: Int)
fun Buffer.readFully(pointer: <ERROR CLASS><<ERROR CLASS>>, offset: Long, length: Int)
fun Input.readFully(dst: <ERROR CLASS><<ERROR CLASS>>, offset: Int, length: Int)
fun Input.readFully(dst: <ERROR CLASS><<ERROR CLASS>>, offset: Long, length: Long)
Link copied to clipboard
fun Buffer.readFullyLittleEndian(dst: DoubleArray, offset: Int = 0, length: Int = dst.size - offset)
fun Buffer.readFullyLittleEndian(dst: FloatArray, offset: Int = 0, length: Int = dst.size - offset)
fun Buffer.readFullyLittleEndian(dst: IntArray, offset: Int = 0, length: Int = dst.size - offset)
fun Buffer.readFullyLittleEndian(dst: LongArray, offset: Int = 0, length: Int = dst.size - offset)
fun Buffer.readFullyLittleEndian(dst: ShortArray, offset: Int = 0, length: Int = dst.size - offset)
fun Buffer.readFullyLittleEndian(dst: UIntArray, offset: Int = 0, length: Int = dst.size - offset)
fun Buffer.readFullyLittleEndian(dst: ULongArray, offset: Int = 0, length: Int = dst.size - offset)
fun Buffer.readFullyLittleEndian(dst: UShortArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFullyLittleEndian(dst: DoubleArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFullyLittleEndian(dst: FloatArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFullyLittleEndian(dst: IntArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFullyLittleEndian(dst: LongArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFullyLittleEndian(dst: ShortArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFullyLittleEndian(dst: UIntArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFullyLittleEndian(dst: ULongArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFullyLittleEndian(dst: UShortArray, offset: Int = 0, length: Int = dst.size - offset)
Link copied to clipboard
@JvmName(name = "readFully")
fun Input.readFullyOld(dst: ByteArray, offset: Int = 0, length: Int = dst.size - offset)
@JvmName(name = "readFully")
fun Input.readFullyOld(dst: DoubleArray, offset: Int = 0, length: Int = dst.size - offset)
@JvmName(name = "readFully")
fun Input.readFullyOld(dst: FloatArray, offset: Int = 0, length: Int = dst.size - offset)
@JvmName(name = "readFully")
fun Input.readFullyOld(dst: IntArray, offset: Int = 0, length: Int = dst.size - offset)
@JvmName(name = "readFully")
fun Input.readFullyOld(dst: LongArray, offset: Int = 0, length: Int = dst.size - offset)
@JvmName(name = "readFully")
fun Input.readFullyOld(dst: ShortArray, offset: Int = 0, length: Int = dst.size - offset)
Link copied to clipboard
fun Buffer.readInt(): Int

Read an integer or fail if not enough bytes available for reading. The numeric value is decoded in the network order (Big Endian).

fun Input.readInt(): Int
inline fun IoBuffer.readInt(): Int
fun Input.readInt(byteOrder: ByteOrder): Int
Link copied to clipboard
fun Buffer.readIntLittleEndian(): Int
fun Input.readIntLittleEndian(): Int
Link copied to clipboard
fun Buffer.readLong(): Long

Read a long integer or fail if not enough bytes available for reading. The numeric value is decoded in the network order (Big Endian).

fun Input.readLong(): Long
inline fun IoBuffer.readLong(): Long
fun Input.readLong(byteOrder: ByteOrder): Long
Link copied to clipboard
fun Buffer.readLongLittleEndian(): Long
fun Input.readLongLittleEndian(): Long
Link copied to clipboard
fun Buffer.readShort(): Short

Read a short integer or fail if no bytes available for reading. The numeric value is decoded in the network order (Big Endian).

fun Input.readShort(): Short
inline fun IoBuffer.readShort(): Short
fun Input.readShort(byteOrder: ByteOrder): Short
Link copied to clipboard
fun Buffer.readShortLittleEndian(): Short
fun Input.readShortLittleEndian(): Short
Link copied to clipboard
fun Buffer.readText(charset: Charset = Charsets.UTF_8, max: Int = Int.MAX_VALUE): String
fun Input.readText(charset: Charset = Charsets.UTF_8, max: Int = Int.MAX_VALUE): String
fun Input.readText(out: Appendable, charset: Charset = Charsets.UTF_8, max: Int = Int.MAX_VALUE): Int

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

fun Input.readText(decoder: CharsetDecoder, max: Int = Int.MAX_VALUE): String
fun Input.readText(out: Appendable, decoder: CharsetDecoder, max: Int = Int.MAX_VALUE): Int

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

fun Buffer.readText(decoder: CharsetDecoder, out: Appendable, lastBuffer: Boolean, max: Int = Int.MAX_VALUE): Int
fun ByteReadPacket.readText(decoder: CharsetDecoder, out: Appendable, max: Int = Int.MAX_VALUE): Int
Link copied to clipboard
fun Input.readTextExact(charset: Charset = Charsets.UTF_8, n: Int): String

Read exactly n characters interpreting bytes in the specified charset.

Link copied to clipboard
fun Input.readTextExactBytes(charset: Charset = Charsets.UTF_8, bytes: Int): String

Read exactly the specified number of bytes interpreting bytes in the specified charset (optional, UTF-8 by default).

fun Input.readTextExactBytes(bytesCount: Int, charset: Charset = Charsets.UTF_8): String

Read exactly bytesCount interpreting bytes in the specified charset (optional, UTF-8 by default).

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

Read exactly charactersCount characters interpreting bytes in the specified charset.

Link copied to clipboard
fun Buffer.readUByte(): UByte

Read an unsigned byte or fail if no bytes available for reading.

inline fun Input.readUByte(): UByte
inline fun IoBuffer.readUByte(): UByte
Link copied to clipboard
fun Buffer.readUInt(): UInt

Read an unsigned integer or fail if not enough bytes available for reading. The numeric value is decoded in the network order (Big Endian).

inline fun Input.readUInt(): UInt
inline fun IoBuffer.readUInt(): UInt
Link copied to clipboard
fun Buffer.readULong(): ULong

Read an unsigned long integer or fail if not enough bytes available for reading. The numeric value is decoded in the network order (Big Endian).

inline fun Input.readULong(): ULong
inline fun IoBuffer.readULong(): ULong
Link copied to clipboard
fun Input.readUntilDelimiter(delimiter: Byte, dst: Output): Long

Copies to dst output until the specified delimiter occurred.

fun Input.readUntilDelimiter(delimiter: Byte, dst: ByteArray, offset: Int = 0, length: Int = dst.size): Int

Copies to dst array at offset at most length bytes or until the specified delimiter occurred.

Link copied to clipboard
fun Input.readUntilDelimiters(delimiter1: Byte, delimiter2: Byte, dst: Output): Long

Copies to dst output until one of the specified delimiters delimiter1 or delimiter2 occurred.

fun Input.readUntilDelimiters(delimiter1: Byte, delimiter2: Byte, dst: ByteArray, offset: Int = 0, length: Int = dst.size): Int

Copies to dst array at offset at most length bytes or until one of the specified delimiters delimiter1 or delimiter2 occurred.

Link copied to clipboard
fun Buffer.readUShort(): UShort

Read an unsigned short integer or fail if not enough bytes available for reading. The numeric value is decoded in the network order (Big Endian).

inline fun Input.readUShort(): UShort
inline fun IoBuffer.readUShort(): UShort
Link copied to clipboard
fun ByteReadPacket.readUTF8Line(estimate: Int = 16, limit: Int = Int.MAX_VALUE): String?
fun Input.readUTF8Line(estimate: Int = 16, limit: Int = Int.MAX_VALUE): String?

Read a string line considering optionally specified estimate but up to optional limit characters length (does fail once limit exceeded) or return null if the packet is empty

Link copied to clipboard
fun Input.readUTF8LineTo(out: Appendable, limit: Int): Boolean

Reads UTF-8 line and append all line characters to out except line endings. Supports CR, LF and CR+LF

Link copied to clipboard
fun Input.readUTF8UntilDelimiter(delimiters: String, limit: Int = Int.MAX_VALUE): String

Reads UTF-8 characters until one of the specified delimiters found, limit exceeded or end of stream encountered

Link copied to clipboard
fun Input.readUTF8UntilDelimiterTo(out: BytePacketBuilderBase, delimiters: String, limit: Int = Int.MAX_VALUE): Int

fun Input.readUTF8UntilDelimiterTo(out: Output, delimiters: String, limit: Int = Int.MAX_VALUE): Int
fun Input.readUTF8UntilDelimiterTo(out: Appendable, delimiters: String, limit: Int = Int.MAX_VALUE): Int

Reads UTF-8 characters to out buffer until one of the specified delimiters found, limit exceeded or end of stream encountered

Link copied to clipboard
fun IoBuffer.release(pool: ObjectPool<IoBuffer>)

releases buffer view and returns it to the pool if there are no more usages. Based on simple ref-counting so it is very fragile.

Link copied to clipboard
fun ChunkBuffer.remainingAll(): Long

Summarize remainings of all elements of the chain

fun remainingAll(buffer: IoBuffer): Long
Link copied to clipboard
fun BytePacketBuilder.reset()

Discard all written bytes and prepare to build another packet.

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

actual 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
inline fun Input.takeWhile(block: (Buffer) -> Boolean)

Invoke block function for every chunk until end of input or block function return falseblock function returns true to request more chunks or false to stop loop

Link copied to clipboard
inline fun Input.takeWhileSize(initialSize: Int = 1, block: (Buffer) -> Int)

Invoke block function for every chunk until end of input or block function return zero block function returns number of bytes required to read next primitive and shouldn't require too many bytes at once otherwise it could fail with an exception. It is not guaranteed that every chunk will have fixed size but it will be always at least requested bytes length. block function should never release provided buffer and should not write to it otherwise an undefined behaviour could be observed

Link copied to clipboard
inline fun String.toByteArray(charset: Charset = Charsets.UTF_8): ByteArray
Link copied to clipboard
fun Buffer.tryPeek(): Int

Peek the next unsigned byte or return -1 if no more bytes available for reading. No bytes will be marked as consumed in any case.

Link copied to clipboard
inline fun <C : Closeable, R> C.use(block: (C) -> R): R
Link copied to clipboard
inline fun <R> withBuffer(pool: ObjectPool<Buffer>, block: Buffer.() -> R): R

Invoke block function with a temporary Buffer instance taken from the specified pool. Depending on the pool it may be safe or unsafe to capture and use the provided buffer outside of the block. Usually it is always recommended to NOT capture an instance outside.

inline fun <R> withBuffer(size: Int, block: Buffer.() -> R): R

Invoke block function with a temporary Buffer instance of the specified size in bytes. The provided instance shouldn't be captured and used outside of the block otherwise an undefined behaviour may occur including crash and/or data corruption.

Link copied to clipboard
inline fun Buffer.write(block: (memory: Memory, start: Int, endExclusive: Int) -> Int): Int

Apply block of code with buffer's memory providing write range indices. The returned value of block lambda should return number of bytes were written. o read/write functions on this buffer should be called inside of block otherwise an undefined behaviour may occur including data damage.

Link copied to clipboard
inline fun BytePacketBuilder.writeByteBufferDirect(size: Int, block: (ByteBuffer) -> Unit): Int

Write bytes directly to packet builder's segment. Generally shouldn't be used in user's code and useful for efficient integration.

Link copied to clipboard
inline fun Buffer.writeDirect(size: Int = 1, block: (ByteBuffer) -> Unit): Int

inline fun BytePacketBuilder.writeDirect(size: Int, block: (ByteBuffer) -> Unit)

Write bytes directly to packet builder's segment. Generally shouldn't be used in user's code and useful for efficient integration.

inline fun Buffer.writeDirect(block: (<ERROR CLASS><<ERROR CLASS>>) -> Int): Int
Link copied to clipboard
fun Buffer.writeDouble(value: Double)

Write a floating point number or fail if not enough space available for writing. The numeric value is encoded in the network order (Big Endian).

inline fun IoBuffer.writeDouble(value: Double)
fun Output.writeDouble(value: Double)
fun Output.writeDouble(value: Double, byteOrder: ByteOrder)
Link copied to clipboard
fun Buffer.writeDoubleLittleEndian(value: Double)
fun Output.writeDoubleLittleEndian(value: Double)
Link copied to clipboard
fun Buffer.writeFloat(value: Float)

Write a floating point number or fail if not enough space available for writing. The numeric value is encoded in the network order (Big Endian).

inline fun IoBuffer.writeFloat(value: Float)
fun Output.writeFloat(value: Float)
fun Output.writeFloat(value: Float, byteOrder: ByteOrder)
Link copied to clipboard
fun Buffer.writeFloatLittleEndian(value: Float)
fun Output.writeFloatLittleEndian(value: Float)
Link copied to clipboard
fun Buffer.writeFully(src: Buffer)

Write all readable bytes from src to this buffer. Fails if not enough space available to write all bytes.

fun Buffer.writeFully(src: Buffer, length: Int)

Write at most length readable bytes from src to this buffer. Fails if not enough space available to write all bytes.

fun Output.writeFully(src: Buffer, length: Int = src.readRemaining)
fun Output.writeFully(src: IoBuffer, length: Int = src.readRemaining)
inline fun IoBuffer.writeFully(source: ByteArray, offset: Int = 0, length: Int = source.size - offset)
fun Output.writeFully(src: Memory, offset: Int, length: Int)
fun Output.writeFully(src: Memory, offset: Long, length: Long)
fun Output.writeFully(src: ByteArray, offset: Int = 0, length: Int = src.size - offset)
fun Output.writeFully(src: DoubleArray, offset: Int = 0, length: Int = src.size - offset)
fun Output.writeFully(src: FloatArray, offset: Int = 0, length: Int = src.size - offset)
fun Output.writeFully(src: IntArray, offset: Int = 0, length: Int = src.size - offset)
fun Output.writeFully(src: LongArray, offset: Int = 0, length: Int = src.size - offset)
fun Output.writeFully(src: ShortArray, offset: Int = 0, length: Int = src.size - offset)
inline fun Output.writeFully(array: UByteArray, offset: Int = 0, length: Int = array.size - offset)
inline fun Output.writeFully(array: UIntArray, offset: Int = 0, length: Int = array.size - offset)
inline fun Output.writeFully(array: ULongArray, offset: Int = 0, length: Int = array.size - offset)
inline fun Output.writeFully(array: UShortArray, offset: Int = 0, length: Int = array.size - offset)

fun Buffer.writeFully(source: ByteArray, offset: Int = 0, length: Int = source.size - offset)
fun Buffer.writeFully(source: UByteArray, offset: Int = 0, length: Int = source.size - offset)

Write the whole source array range staring at offset and having the specified bytes length.

fun Buffer.writeFully(source: DoubleArray, offset: Int = 0, length: Int = source.size - offset)
fun Buffer.writeFully(source: FloatArray, offset: Int = 0, length: Int = source.size - offset)
fun Buffer.writeFully(source: IntArray, offset: Int = 0, length: Int = source.size - offset)
fun Buffer.writeFully(source: LongArray, offset: Int = 0, length: Int = source.size - offset)
fun Buffer.writeFully(source: ShortArray, offset: Int = 0, length: Int = source.size - offset)
fun Buffer.writeFully(source: UIntArray, offset: Int = 0, length: Int = source.size - offset)
fun Buffer.writeFully(source: ULongArray, offset: Int = 0, length: Int = source.size - offset)
fun Buffer.writeFully(source: UShortArray, offset: Int = 0, length: Int = source.size - offset)

Write the whole source array range staring at offset and having the specified items length. Numeric values are interpreted in the network byte order (Big Endian).

fun Buffer.writeFully(source: ByteBuffer)

Write source buffer content moving its position.

fun BytePacketBuilder.writeFully(src: ByteBuffer)

Write all src buffer remaining bytes and change it's position accordingly

fun Output.writeFully(bb: ByteBuffer)
fun BytePacketBuilder.writeFully(src: <ERROR CLASS><<ERROR CLASS>>, size: Int)

Write all remaining src buffer bytes and change its position accordingly

fun Buffer.writeFully(pointer: <ERROR CLASS><<ERROR CLASS>>, offset: Int, length: Int)
fun Buffer.writeFully(pointer: <ERROR CLASS><<ERROR CLASS>>, offset: Long, length: Int)
fun Output.writeFully(src: <ERROR CLASS><<ERROR CLASS>>, offset: Int, length: Int)
fun Output.writeFully(src: <ERROR CLASS><<ERROR CLASS>>, offset: Long, length: Long)
Link copied to clipboard
fun Buffer.writeFullyLittleEndian(source: DoubleArray, offset: Int = 0, length: Int = source.size - offset)
fun Buffer.writeFullyLittleEndian(source: FloatArray, offset: Int = 0, length: Int = source.size - offset)
fun Buffer.writeFullyLittleEndian(source: IntArray, offset: Int = 0, length: Int = source.size - offset)
fun Buffer.writeFullyLittleEndian(source: LongArray, offset: Int = 0, length: Int = source.size - offset)
fun Buffer.writeFullyLittleEndian(source: ShortArray, offset: Int = 0, length: Int = source.size - offset)
fun Buffer.writeFullyLittleEndian(source: UIntArray, offset: Int = 0, length: Int = source.size - offset)
fun Buffer.writeFullyLittleEndian(source: ULongArray, offset: Int = 0, length: Int = source.size - offset)
fun Buffer.writeFullyLittleEndian(source: UShortArray, offset: Int = 0, length: Int = source.size - offset)
fun Output.writeFullyLittleEndian(source: DoubleArray, offset: Int = 0, length: Int = source.size - offset)
fun Output.writeFullyLittleEndian(source: FloatArray, offset: Int = 0, length: Int = source.size - offset)
fun Output.writeFullyLittleEndian(source: IntArray, offset: Int = 0, length: Int = source.size - offset)
fun Output.writeFullyLittleEndian(source: LongArray, offset: Int = 0, length: Int = source.size - offset)
fun Output.writeFullyLittleEndian(source: ShortArray, offset: Int = 0, length: Int = source.size - offset)
fun Output.writeFullyLittleEndian(source: UIntArray, offset: Int = 0, length: Int = source.size - offset)
fun Output.writeFullyLittleEndian(source: ULongArray, offset: Int = 0, length: Int = source.size - offset)
fun Output.writeFullyLittleEndian(source: UShortArray, offset: Int = 0, length: Int = source.size - offset)
Link copied to clipboard
fun Buffer.writeInt(value: Int)

Write an integer or fail if not enough space available for writing. The numeric value is encoded in the network order (Big Endian).

inline fun IoBuffer.writeInt(value: Int)
fun Output.writeInt(value: Int)
fun Output.writeInt(value: Int, byteOrder: ByteOrder)
Link copied to clipboard
fun Buffer.writeIntLittleEndian(value: Int)
fun Output.writeIntLittleEndian(value: Int)
Link copied to clipboard
fun Buffer.writeLong(value: Long)

Write a long integer or fail if not enough space available for writing. The numeric value is encoded in the network order (Big Endian).

inline fun IoBuffer.writeLong(value: Long)
fun Output.writeLong(value: Long)
fun Output.writeLong(value: Long, byteOrder: ByteOrder)
Link copied to clipboard
fun Buffer.writeLongLittleEndian(value: Long)
fun Output.writeLongLittleEndian(value: Long)
Link copied to clipboard
fun Output.writePacket(packet: ByteReadPacket)
Link copied to clipboard
fun Buffer.writeShort(value: Short)

Write a short integer or fail if not enough space available for writing. The numeric value is encoded in the network order (Big Endian).

inline fun IoBuffer.writeShort(value: Short)
fun Output.writeShort(value: Short)
fun Output.writeShort(value: Short, byteOrder: ByteOrder)
Link copied to clipboard
fun Buffer.writeShortLittleEndian(value: Short)
fun Output.writeShortLittleEndian(value: Short)
Link copied to clipboard
fun Output.writeText(text: CharArray, fromIndex: Int = 0, toIndex: Int = text.size, charset: Charset = Charsets.UTF_8)
fun Output.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

fun Output.writeText(text: CharSequence, fromIndex: Int = 0, toIndex: Int = text.length, encoder: CharsetEncoder)

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

Link copied to clipboard
fun Buffer.writeUByte(value: UByte)

Write an unsigned byte or fail if not enough space available for writing.

fun IoBuffer.writeUByte(value: UByte)
inline fun Output.writeUByte(v: UByte)
Link copied to clipboard
fun Buffer.writeUInt(value: UInt)

Write an unsigned integer or fail if not enough space available for writing. The numeric value is encoded in the network order (Big Endian).

inline fun IoBuffer.writeUInt(value: UInt)
inline fun Output.writeUInt(v: UInt)
Link copied to clipboard
fun Buffer.writeULong(value: ULong)

Write an unsigned long integer or fail if not enough space available for writing. The numeric value is encoded in the network order (Big Endian).

inline fun IoBuffer.writeULong(value: ULong)
inline fun Output.writeULong(v: ULong)
Link copied to clipboard
fun Buffer.writeUShort(value: UShort)

Write an unsigned short integer or fail if not enough space available for writing. The numeric value is encoded in the network order (Big Endian).

inline fun IoBuffer.writeUShort(value: UShort)
inline fun Output.writeUShort(v: UShort)
Link copied to clipboard
inline fun Output.writeWhile(block: (Buffer) -> Boolean)

Append number of chunks invoking block function while the returned value is true. Depending on the output underlying implementation it could invoke block function with the same buffer several times however it is guaranteed that it is always non-empty.

Link copied to clipboard
inline fun Output.writeWhileSize(initialSize: Int = 1, block: (Buffer) -> Int)

Append number of chunks invoking block function while the returned value is positive. If returned value is positive then it will be invoked again with a buffer having at least requested number of bytes space (could be the same buffer as before if it complies to the restriction).

Properties

Link copied to clipboard
var Buffer.byteOrder: ByteOrder
Link copied to clipboard
val Input.isEmpty: Boolean

For streaming input it should be Input.endOfInput instead.

Link copied to clipboard
val ByteReadPacket.isEmpty: Boolean
Link copied to clipboard
val Input.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 ByteReadPacket.isNotEmpty: Boolean
Link copied to clipboard
expect val PACKET_MAX_COPY_SIZE: Int = 200
actual val PACKET_MAX_COPY_SIZE: Int = 200
actual val PACKET_MAX_COPY_SIZE: Int = 200