ByteReadChannel
interface ByteReadChannel
Channel for asynchronous reading of sequences of bytes. This is a single-reader channel.
Operations on this channel cannot be invoked concurrently.
Properties
abstract val availableForRead: Int Returns number of bytes that can be read without suspension. Read operations do no suspend and return immediately when this number is at least the number of bytes requested for read. |
|
abstract val isClosedForRead: Boolean Returns |
|
abstract val isClosedForWrite: Boolean |
|
abstract var readByteOrder: ByteOrder Byte order that is used for multi-byte read operations (such as readShort, readInt, readLong, readFloat, and readDouble). |
|
abstract val totalBytesRead: Long Number of bytes read from the channel. It is not guaranteed to be atomic so could be updated in the middle of long running read operation. |
Functions
Close channel with optional cause cancellation. Unlike ByteWriteChannel.close that could close channel normally, cancel does always close with error so any operations on this channel will always fail and all suspensions will be resumed with exception. |
|
abstract suspend fun consumeEachBufferRange( For every available bytes range invokes visitor function until it return false or end of stream encountered |
|
Discard up to max bytes |
|
abstract fun <R> lookAhead( |
|
abstract suspend fun <R> lookAheadSuspend( |
|
abstract suspend fun read( Invokes block 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. |
|
Reads all available bytes to dst buffer and returns immediately or suspends if no bytes available abstract suspend fun readAvailable(dst: ByteBuffer): Int abstract suspend fun readAvailable(dst: BufferView): Int |
|
abstract suspend fun readBoolean(): Boolean Reads a boolean value (suspending if no bytes available yet) or fails if channel has been closed and not enough bytes. |
|
abstract suspend fun readByte(): Byte Reads a byte (suspending if no bytes available yet) or fails if channel has been closed and not enough bytes. |
|
abstract suspend fun readDouble(): Double Reads double number (suspending if not enough bytes available) or fails if channel has been closed and not enough bytes. |
|
abstract suspend fun readFloat(): Float Reads float number (suspending if not enough bytes available) or fails if channel has been closed and not enough bytes. |
|
Reads all length bytes to dst buffer or fails if channel has been closed. Suspends if not enough bytes available. abstract suspend fun readFully(dst: ByteBuffer): Int |
|
abstract suspend fun readInt(): Int Reads an int number (suspending if not enough bytes available) or fails if channel has been closed and not enough bytes. |
|
abstract suspend fun readLong(): Long Reads a long number (suspending if not enough bytes available) or fails if channel has been closed and not enough bytes. |
|
abstract suspend fun readPacket( Reads the specified amount of bytes and makes a byte packet from them. Fails if channel has been closed and not enough bytes available. Accepts headerSizeHint to be provided, see WritePacket. |
|
abstract suspend fun readShort(): Short Reads a short number (suspending if not enough bytes available) or fails if channel has been closed and not enough bytes. |
|
Reads a line of UTF-8 characters to the specified out buffer up to limit characters. Supports both CR-LF and LF line endings. Throws an exception if the specified limit has been exceeded. |
Extension Functions
suspend fun ByteReadChannel.copyAndClose( Reads all the bytes from receiver channel and writes them to dst channel and then closes it. Closes dst channel if fails to read or write with cause exception. |
|
suspend fun ByteReadChannel.copyTo( Reads up to limit bytes from receiver channel and writes them to dst channel. Closes dst channel if fails to read or write with cause exception. |
|
suspend fun ByteReadChannel.copyTo( Copies up to limit bytes from this byte channel to out stream suspending on read channel and blocking on output |
|
suspend fun ByteReadChannel.copyTo( Copy up to limit bytes to blocking NIO channel. Copying to non-blocking channel requires selection and not supported. It does suspend if no data available in byte channel but may block if destination NIO channel blocks. suspend fun ByteReadChannel.copyTo( Copy up to limit bytes to blocking pipe. A shortcut to copyTo function with NIO channel destination |
|
suspend fun ByteReadChannel.joinTo( |
|
suspend fun ByteReadChannel.readASCIILine( |
|
suspend fun ByteReadChannel. |
|
suspend fun ByteReadChannel.readRemaining( Reads all the bytes from receiver channel and builds a packet that is returned unless the specified limit exceeded. It will simply stop reading and return packet of size limit in this case |
|
suspend fun ByteReadChannel.readUTF8Line( |
|
suspend fun ByteReadChannel.readUntilDelimiter( Reads from the channel to the specified dst byte buffer until one of the following: |
|
suspend fun ByteReadChannel.skipDelimiter( |
|
fun ByteReadChannel.toInputStream( 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 |
Inheritors
interface ByteChannel : ByteReadChannel, ByteWriteChannel Channel for asynchronous reading and writing of sequences of bytes. This is a buffered single-reader single-writer channel. |