ByteChannelSequentialJVM

class ByteChannelSequentialJVM(initial: IoBuffer, autoFlush: Boolean) : ByteChannelSequentialBase

Functions

Link copied to clipboard
open override fun attachJob(job: Job)
Link copied to clipboard
open suspend override fun await(atLeast: Int): Boolean

Suspend until atLeast bytes become available or end of stream encountered (possibly due to exceptional close)

Link copied to clipboard
open suspend override fun awaitContent()
Link copied to clipboard
open suspend override fun awaitFreeSpace()
Link copied to clipboard
open override fun beginWriteSession(): WriterSuspendSession
Link copied to clipboard
open override fun cancel(cause: Throwable?): Boolean

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.

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

Closes this channel with an optional exceptional cause. It flushes all pending write bytes (via flush). This is an idempotent operation -- repeated invocations of this function have no effect and return false.

Link copied to clipboard
open suspend override fun consumeEachBufferRange(visitor: ConsumeEachBufferVisitor)

For every available bytes range invokes visitor function until it return false or end of stream encountered

Link copied to clipboard
open override fun discard(n: Int): Int

Discard at most n available bytes or 0 if no bytes available yet

open suspend override fun discard(max: Long): Long

Discard up to max bytes

Link copied to clipboard
open override fun endReadSession()
Link copied to clipboard
open override fun endWriteSession(written: Int)
Link copied to clipboard
open override fun flush()

Flushes all pending write bytes making them available for read.

Link copied to clipboard
open override fun <R> lookAhead(visitor: LookAheadSession.() -> R): R
Link copied to clipboard
open suspend override fun <R> lookAheadSuspend(visitor: suspend LookAheadSuspendSession.() -> R): R
Link copied to clipboard
suspend override fun peekTo(destination: Memory, destinationOffset: Long, offset: Long, min: Long, max: Long): Long

Try to 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 after skipping offset bytes then it will trigger the underlying source reading first and after that will simply copy available bytes even if EOF encountered so min is not a requirement but a desired number of bytes. It is safe to specify max greater than the destination free space. min shouldn't be bigger than the destination free space. This function could trigger the underlying source suspending reading. It is allowed to specify too big offset so in this case this function will always return 0 after prefetching all underlying bytes but note that it may lead to significant memory consumption. 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 endOfInput.

Link copied to clipboard
open suspend override fun read(min: Int, 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
open suspend override fun readAvailable(dst: IoBuffer): Int
open suspend override fun readAvailable(dst: ByteBuffer): Int

open override fun readAvailable(min: Int, block: (ByteBuffer) -> Unit): Int

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.

open suspend override fun readAvailable(dst: ByteArray, 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
open suspend override fun readBoolean(): Boolean

Reads a boolean value (suspending if no bytes available yet) or fails if channel has been closed and not enough bytes.

Link copied to clipboard
open suspend override fun readByte(): Byte

Reads a byte (suspending if no bytes available yet) or fails if channel has been closed and not enough bytes.

Link copied to clipboard
open suspend override fun readDouble(): Double

Reads double number (suspending if not enough bytes available) or fails if channel has been closed and not enough bytes.

Link copied to clipboard
open suspend override fun readFloat(): Float

Reads float number (suspending if not enough bytes available) or fails if channel has been closed and not enough bytes.

Link copied to clipboard
open suspend override fun readFully(dst: ByteBuffer): Int
open suspend override fun readFully(dst: IoBuffer, n: Int)

open suspend override fun readFully(dst: ByteArray, offset: Int, length: Int)

Reads all length bytes to dst buffer or fails if channel has been closed. Suspends if not enough bytes available.

Link copied to clipboard
open suspend override fun readInt(): Int

Reads an int number (suspending if not enough bytes available) or fails if channel has been closed and not enough bytes.

Link copied to clipboard
open suspend override fun readLong(): Long

Reads a long number (suspending if not enough bytes available) or fails if channel has been closed and not enough bytes.

Link copied to clipboard
open suspend override fun readPacket(size: Int, headerSizeHint: Int): ByteReadPacket

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.

Link copied to clipboard
open suspend override fun readRemaining(limit: Long, headerSizeHint: Int): ByteReadPacket

Reads up to limit bytes and makes a byte packet or until end of stream encountered. Accepts headerSizeHint to be provided, see BytePacketBuilder.

Link copied to clipboard
open override fun readSession(consumer: ReadSession.() -> Unit)

Starts non-suspendable read session. After channel preparation consumer lambda will be invoked immediately even if there are no bytes available for read yet.

Link copied to clipboard
open suspend override fun readShort(): Short

Reads a short number (suspending if not enough bytes available) or fails if channel has been closed and not enough bytes.

Link copied to clipboard
open suspend override fun readSuspendableSession(consumer: suspend SuspendableReadSession.() -> Unit)

Starts a suspendable read session. After channel preparation consumer lambda will be invoked immediately even if there are no bytes available for read yet. consumer lambda could suspend as much as needed.

Link copied to clipboard
open suspend override fun readUTF8Line(limit: Int): String?

Reads a line of UTF-8 characters up to limit characters. Supports both CR-LF and LF line endings. Throws an exception if the specified limit has been exceeded.

Link copied to clipboard
open suspend override fun <A : Appendable> readUTF8LineTo(out: A, limit: Int): Boolean

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.

Link copied to clipboard
open override fun request(atLeast: Int): IoBuffer?

Request buffer range atLeast bytes length

Link copied to clipboard
open override fun startReadSession(): SuspendableReadSession
Link copied to clipboard
open suspend override fun write(min: Int, block: (ByteBuffer) -> Unit)

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

Link copied to clipboard
open suspend override fun writeAvailable(src: IoBuffer): Int
open suspend override fun writeAvailable(src: ByteBuffer): Int

open override fun writeAvailable(min: Int, block: (ByteBuffer) -> Unit): Int

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

open suspend override fun writeAvailable(src: ByteArray, offset: Int, length: Int): Int

Writes as much as possible and only suspends if buffer is full

Link copied to clipboard
open suspend override fun writeByte(b: Byte)

Writes byte and suspends until written. Crashes if channel get closed while writing.

Link copied to clipboard
open suspend override fun writeDouble(d: Double)

Writes double number and suspends until written. Crashes if channel get closed while writing.

Link copied to clipboard
open suspend override fun writeFloat(f: Float)

Writes float number and suspends until written. Crashes if channel get closed while writing.

Link copied to clipboard
open suspend override fun writeFully(src: Buffer)
open suspend override fun writeFully(src: IoBuffer)
open suspend override fun writeFully(src: ByteBuffer)
open suspend override fun writeFully(memory: Memory, startIndex: Int, endIndex: Int)

open suspend override fun writeFully(src: ByteArray, offset: Int, length: Int)

Writes all src bytes and suspends until all bytes written. Causes flush if buffer filled up or when autoFlush Crashes if channel get closed while writing.

Link copied to clipboard
open suspend override fun writeInt(i: Int)

Writes int number and suspends until written. Crashes if channel get closed while writing.

Link copied to clipboard
open suspend override fun writeLong(l: Long)

Writes long number and suspends until written. Crashes if channel get closed while writing.

Link copied to clipboard
open suspend override fun writePacket(packet: ByteReadPacket)

Writes a packet fully or fails if channel get closed before the whole packet has been written

Link copied to clipboard
open suspend override fun writeShort(s: Short)

Writes short number and suspends until written. Crashes if channel get closed while writing.

Link copied to clipboard
open suspend override fun writeSuspendSession(visitor: suspend WriterSuspendSession.() -> Unit)
Link copied to clipboard
open suspend override fun writeWhile(block: (ByteBuffer) -> Boolean)

Invokes block for every free buffer until it return false. It will also suspend every time when no free space available for write.

Properties

Link copied to clipboard
open override val autoFlush: Boolean

Returns true if channel flushes automatically all pending bytes after every write function call. If false then flush only happens at manual flush invocation or when the buffer is full.

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

Link copied to clipboard
open override val availableForWrite: Int

Returns number of bytes that can be written without suspension. Write operations do no suspend and return immediately when this number is at least the number of bytes requested for write.

Link copied to clipboard
override var closedCause: Throwable?

A closure causes exception or null if closed successfully or not yet closed

Link copied to clipboard
open override val isClosedForRead: Boolean

Returns true if the channel is closed and no remaining bytes are available for read. It implies that availableForRead is zero.

Link copied to clipboard
open override val isClosedForWrite: Boolean

Returns true is channel has been closed and attempting to write to the channel will cause an exception.

Link copied to clipboard
open override var readByteOrder: ByteOrder

Byte order that is used for multi-byte read operations (such as readShort, readInt, readLong, readFloat, and readDouble).

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

Link copied to clipboard
open override val totalBytesWritten: Long

Number of bytes written to the channel. It is not guaranteed to be atomic so could be updated in the middle of write operation.

Link copied to clipboard
open override var writeByteOrder: ByteOrder

Byte order that is used for multi-byte write operations (such as writeShort, writeInt, writeLong, writeFloat, and writeDouble).