ktor-io / io.ktor.utils.io.nio / java.nio.channels.ReadableByteChannel

Extensions for java.nio.channels.ReadableByteChannel

asInput

fun ReadableByteChannel.asInput(pool: ObjectPool<ChunkBuffer> = ChunkBuffer.Pool): Input

read

fun ReadableByteChannel.read(buffer: IoBuffer): Int

Does the same as ReadableByteChannel.read but to a IoBuffer instance

fun ReadableByteChannel.read(buffer: Buffer): Int

Does the same as ReadableByteChannel.read but to a Buffer instance

fun ReadableByteChannel.read(destination: Memory, destinationOffset: Int = 0, maxLength: Int = destination.size32 - destinationOffset): Int

Does the same as ReadableByteChannel.read but to a Memory instance

readPacketAtLeast

fun ReadableByteChannel.readPacketAtLeast(n: Long): ByteReadPacket

Read a packet of at least n bytes or all remaining. Does fail if not enough bytes remaining. . This function is useless with non-blocking channels

readPacketAtMost

fun ReadableByteChannel.readPacketAtMost(n: Long): ByteReadPacket

Read a packet of at most n bytes. Resulting packet could be empty however this function does always reads as much bytes as possible. You also can use it with non-blocking channels

readPacketExact

fun ReadableByteChannel.readPacketExact(n: Long): ByteReadPacket

Read a packet of exactly n bytes. This function is useless with non-blocking channels