asByteWriteChannel
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
Content copied to clipboard
All operations on the ByteWriteChannel are buffered: the underlying OutputStream will be receiving bytes when the ByteWriteChannel.flush happens.