All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jvmMain.kotlinx.io.nio.Output.kt Maven / Gradle / Ivy

There is a newer version: 0.1.16
Show newest version
package kotlinx.io.nio

import kotlinx.io.core.*
import kotlinx.io.pool.*
import java.nio.channels.*

private class ChannelAsOutput(pool: ObjectPool,
                              val channel: WritableByteChannel
) : AbstractOutput(pool) {
    override fun flush(buffer: IoBuffer) {
        buffer.readDirect { bb ->
            while (bb.hasRemaining()) {
                channel.write(bb)
            }
        }
    }

    override fun closeDestination() {
        channel.close()
    }
}

fun WritableByteChannel.asOutput(pool: ObjectPool = IoBuffer.Pool): Output
        = ChannelAsOutput(pool, this)




© 2015 - 2025 Weber Informatics LLC | Privacy Policy