ByteChannel

Sequential (non-concurrent) byte channel implementation

Constructors

Link copied to clipboard
constructor(autoFlush: Boolean = false)

Properties

Link copied to clipboard
val autoFlush: Boolean = false
Link copied to clipboard
Link copied to clipboard
open override val closedCause: Throwable?
Link copied to clipboard
open override val isClosedForRead: Boolean
Link copied to clipboard
open override val isClosedForWrite: Boolean
Link copied to clipboard
open override val readBuffer: Source
Link copied to clipboard
Link copied to clipboard
open override val writeBuffer: Sink

Functions

Link copied to clipboard
fun ByteChannel.attachJob(job: Job)

Ensures that when the given job is canceled, the ByteChannel is canceled with the same exception.

Link copied to clipboard
open suspend override fun awaitContent(min: Int): Boolean

Suspend the channel until it has min bytes or gets closed. Throws exception if the channel was closed with an error. If there are bytes available in the channel, this function returns immediately.

Link copied to clipboard
Link copied to clipboard
open override fun cancel(cause: Throwable?)
Link copied to clipboard
Link copied to clipboard
open override fun close()

Flush all pending bytes from writeBuffer to the internal read buffer without suspension and initiate channel close.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
suspend fun ByteReadChannel.copyTo(channel: ByteWriteChannel, limit: Long): Long
Link copied to clipboard
suspend fun ByteReadChannel.discard(max: Long = Long.MAX_VALUE): Long
Link copied to clipboard
suspend fun ByteReadChannel.discardExact(value: Long)
Link copied to clipboard

Suspends the channel until it is exhausted or gets closed. If the read buffer is empty, it suspends until there are bytes available in the channel. Once the channel is exhausted or closed, this function returns.

Link copied to clipboard
open suspend override fun flush()
Link copied to clipboard
open suspend override fun flushAndClose()
Link copied to clipboard
Link copied to clipboard
open override fun flushWriteBuffer()

Flush all pending bytes from writeBuffer to the internal read buffer without suspension.

Link copied to clipboard
suspend fun ByteReadChannel.peek(count: Int): ByteString?

Retrieves, but does not consume, up to the specified number of bytes from the current position in this ByteReadChannel.

Link copied to clipboard
inline suspend fun ByteReadChannel.read(crossinline block: suspend (ByteArray, Int, Int) -> Int): Int
Link copied to clipboard
fun ByteReadChannel.readAvailable(min: Int, block: (Buffer) -> Int): Int

Invokes block if it is possible to read at least min byte providing buffer to it so lambda can read from the buffer up to Buffer.readRemaining bytes. If there are no min bytes available then the invocation returns -1.

suspend fun ByteReadChannel.readAvailable(buffer: ByteArray, offset: Int = 0, length: Int = buffer.size - offset): Int

Reads all available bytes to dst buffer and returns immediately or suspends if no bytes available

suspend fun ByteReadChannel.readAvailable(dst: CPointer<ByteVar>, offset: Int, length: Int): Int

Reads all available bytes to dst buffer and returns immediately or suspends if no bytes available

Link copied to clipboard
suspend fun ByteReadChannel.readBuffer(): Buffer
suspend fun ByteReadChannel.readBuffer(max: Int): Buffer
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
suspend fun ByteReadChannel.readFully(out: ByteArray, start: Int = 0, end: Int = out.size)

Reads bytes from start to end into the provided out buffer, or fails if the channel has been closed.

Link copied to clipboard
suspend fun ByteReadChannel.readInt(): Int
Link copied to clipboard
Link copied to clipboard
suspend fun ByteReadChannel.readPacket(packet: Int): Source

Reads a packet of packet bytes from the channel.

Link copied to clipboard
suspend fun ByteReadChannel.readRemaining(): Source
suspend fun ByteReadChannel.readRemaining(max: Long): Source
Link copied to clipboard
Link copied to clipboard
suspend fun ByteReadChannel.readUntil(matchString: ByteString, writeChannel: ByteWriteChannel, limit: Long = Long.MAX_VALUE, ignoreMissing: Boolean = false): Long

Reads bytes from the ByteReadChannel until a specified sequence of bytes is encountered or the specified limit is reached.

Link copied to clipboard
suspend fun ByteReadChannel.readUTF8Line(max: Int = Int.MAX_VALUE): String?

Reads a line of UTF-8 characters from the ByteReadChannel. It recognizes CR, LF and CRLF as line delimiters.

Link copied to clipboard
suspend fun ByteReadChannel.readUTF8LineTo(out: Appendable, max: Int = Int.MAX_VALUE): Boolean

Reads a line of UTF-8 characters to the specified out buffer. It recognizes CR, LF and CRLF as a line delimiter.

Link copied to clipboard
suspend fun ByteReadChannel.skipIfFound(byteString: ByteString): Boolean

Skips the specified byteString in the ByteReadChannel if it is found at the current position.

Link copied to clipboard
Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
suspend fun ByteWriteChannel.write(desiredSpace: Int = 1, block: (ByteArray, Int, Int) -> Int): Int

Await for desiredSpace will be available for write and invoke block function providing Memory instance and the corresponding range suitable for wiring in the memory. The block function should return number of bytes were written, possibly 0.

Link copied to clipboard
suspend fun ByteWriteChannel.writeBuffer(value: RawSource)
Link copied to clipboard
suspend fun ByteWriteChannel.writeByte(value: Byte)
Link copied to clipboard
Link copied to clipboard
suspend fun ByteWriteChannel.writeFully(value: ByteArray, startIndex: Int = 0, endIndex: Int = value.size)
suspend fun ByteWriteChannel.writeFully(value: CPointer<ByteVar>, offset: Int, length: Int)
suspend fun ByteWriteChannel.writeFully(src: CPointer<ByteVar>, offset: Long, length: Long)
Link copied to clipboard
suspend fun ByteWriteChannel.writeInt(value: Int)
Link copied to clipboard
suspend fun ByteWriteChannel.writeLong(value: Long)
Link copied to clipboard
suspend fun ByteWriteChannel.writePacket(copy: Buffer)
suspend fun ByteWriteChannel.writePacket(copy: Source)
Link copied to clipboard
suspend fun ByteWriteChannel.writeShort(value: Short)
Link copied to clipboard
suspend fun ByteWriteChannel.writeSource(source: Source)
Link copied to clipboard
suspend fun ByteWriteChannel.writeString(value: String)
Link copied to clipboard