ByteWriteChannel
interface ByteWriteChannel
Channel for asynchronous writing of sequences of bytes. This is a single-writer channel.
Operations on this channel cannot be invoked concurrently, unless explicitly specified otherwise in description. Exceptions are close and flush.
Properties
abstract val autoFlush: Boolean Returns |
|
abstract 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. |
|
abstract val closedCause: Throwable? An closure cause exception or |
|
abstract val isClosedForWrite: Boolean Returns |
|
abstract 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. |
|
abstract var writeByteOrder: ByteOrder Byte order that is used for multi-byte write operations (such as writeShort, writeInt, writeLong, writeFloat, and writeDouble). |
Functions
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 |
|
abstract fun flush(): Unit Flushes all pending write bytes making them available for read. |
|
abstract suspend fun write( 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. |
|
Writes as much as possible and only suspends if buffer is full abstract suspend fun writeAvailable(src: ByteBuffer): Int abstract suspend fun writeAvailable(src: BufferView): Int |
|
Writes byte and suspends until written. Crashes if channel get closed while writing. |
|
Writes double number and suspends until written. Crashes if channel get closed while writing. |
|
Writes float number and suspends until written. Crashes if channel get closed while writing. |
|
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. abstract suspend fun writeFully(src: ByteBuffer): Unit abstract suspend fun writeFully(src: BufferView): Unit |
|
Writes int number and suspends until written. Crashes if channel get closed while writing. |
|
Writes long number and suspends until written. Crashes if channel get closed while writing. |
|
abstract suspend fun writePacket( Writes a packet fully or fails if channel get closed before the whole packet has been written |
|
Writes short number and suspends until written. Crashes if channel get closed while writing. |
|
abstract suspend fun writeSuspendSession( |
|
abstract suspend fun writeWhile( Invokes block for every free buffer until it return |
Extension Functions
fun ByteWriteChannel.toOutputStream( Create blocking java.io.OutputStream for this channel that does block every time the channel suspends at write Similar to do reading in runBlocking however you can pass it to regular blocking API |
|
suspend fun ByteWriteChannel. suspend fun ByteWriteChannel. |
|
suspend fun ByteWriteChannel.writeBoolean(b: Boolean): Unit |
|
suspend fun ByteWriteChannel.writeByte(b: Int): Unit |
|
suspend fun ByteWriteChannel.writeBytes(s: String): Unit |
|
suspend fun ByteWriteChannel.writeChar(ch: Char): Unit Writes UTF16 character |
|
suspend fun ByteWriteChannel.writeChars(s: String): Unit |
|
suspend fun ByteWriteChannel.writeInt(i: Long): Unit |
|
suspend fun ByteWriteChannel.writePacket( |
|
suspend fun ByteWriteChannel.writePacketSuspend( |
|
suspend fun ByteWriteChannel.writeShort(s: Int): Unit |
|
suspend fun ByteWriteChannel.writeStringUtf8( suspend fun ByteWriteChannel.writeStringUtf8( suspend fun ByteWriteChannel.writeStringUtf8(s: String): Unit |
|
suspend fun ByteWriteChannel. |
Inheritors
interface ByteChannel : ByteReadChannel, ByteWriteChannel Channel for asynchronous reading and writing of sequences of bytes. This is a buffered single-reader single-writer channel. |