ByteReadChannel

Channel for asynchronous reading of sequences of bytes. This is a single-reader channel.

Operations on this channel cannot be invoked concurrently.

Report a problem

Inheritors

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
Link copied to clipboard
abstract val closedCause: Throwable?
Link copied to clipboard
abstract val isClosedForRead: Boolean
Link copied to clipboard
abstract val readBuffer: Source
Link copied to clipboard

Functions

Link copied to clipboard

Converts the current ByteReadChannel instance into a RawSource. This enables the usage of a ByteReadChannel as a RawSource for reading operations.

Link copied to clipboard
abstract suspend fun awaitContent(min: Int = 1): 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
abstract fun cancel(cause: Throwable?)
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
suspend fun ByteReadChannel.copyTo(channel: ByteWriteChannel, limit: Long): Long
suspend fun ByteReadChannel.copyTo(channel: WritableByteChannel, limit: Long = Long.MAX_VALUE): Long

Copy up to limit bytes to blocking NIO channel. Copying to a non-blocking channel requires selection and not supported. It is suspended if no data are available in a byte channel but may block if destination NIO channel blocks.

suspend fun ByteReadChannel.copyTo(out: OutputStream, limit: Long = Long.MAX_VALUE): Long

Copies up to limit bytes from this byte channel to out stream suspending on read channel and blocking on output

Link copied to clipboard
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
suspend fun ByteReadChannel.lookAhead(block: suspend LookAheadSuspendSession.() -> Unit)
Link copied to clipboard
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
inline suspend fun ByteReadChannel.read(min: Int = 1, noinline consumer: (ByteBuffer) -> Unit)

Invokes consumer when it will be possible to read at least min bytes providing byte buffer to it so lambda can read from the buffer up to ByteBuffer.remaining bytes. If there are no min bytes available then the invocation could suspend until the requirement will be met.

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 buffer and returns immediately or suspends if no bytes available

Reads bytes from the channel and writes them to the buffer up to its limit. If the channel's read buffer is exhausted, it suspends until there are bytes available.

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

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

Reads a 32-bit floating-point value from the current ByteReadChannel.

Link copied to clipboard

Reads a 32-bit floating-point value from the current ByteReadChannel.

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.

suspend fun ByteReadChannel.readFully(buffer: ByteBuffer)

Reads data from the ByteReadChannel into the provided buffer until the buffer is fully filled or EOF is reached.

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
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.

suspend fun ByteReadChannel.readUTF8LineTo(out: Appendable, max: Int = Int.MAX_VALUE, lineEnding: LineEndingMode = LineEndingMode.Any): Boolean

Reads a line of UTF-8 characters to the specified out buffer. It recognizes the specified line ending as a line delimiter and throws an exception if an unexpected line delimiter is found. By default, all line endings (CR, LF and CRLF) are allowed as a line delimiter.

Link copied to clipboard
suspend fun ByteReadChannel.skipDelimiter(delimiter: ByteBuffer)
suspend fun ByteReadChannel.skipDelimiter(delimiter: ByteString)
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

Create blocking java.io.InputStream for this channel that does block every time the channel suspends at read Similar to do reading in runBlocking however you can pass it to regular blocking API