asByteWriteChannel

fun OutputStream.asByteWriteChannel(): <Error class: unknown class>

Converts this OutputStream into a ByteWriteChannel, enabling asynchronous writing of byte sequences.

val outputStream: OutputStream = FileOutputStream("file.txt")
val channel: ByteWriteChannel = outputStream.asByteWriteChannel()
channel.writeFully("Hello, World!".toByteArray())
channel.flushAndClose() // Ensure the data is written to the OutputStream

All operations on the ByteWriteChannel are buffered: the underlying OutputStream will be receiving bytes when the ByteWriteChannel.flush happens.

Report a problem