com.huanshankeji.vertx.core.okio.VertxBufferWriteStreamSink.kt Maven / Gradle / Ivy
package com.huanshankeji.vertx.core.okio
import io.vertx.core.buffer.Buffer
import io.vertx.core.streams.WriteStream
import io.vertx.kotlin.coroutines.coAwait
import kotlinx.coroutines.runBlocking
import okio.Sink
import okio.Timeout
import okio.buffer
@JvmInline
value class VertxBufferWriteStreamSink(val writeStream: WriteStream) : Sink {
override fun write(source: okio.Buffer, byteCount: Long) {
runBlocking {
writeStream.write(Buffer.buffer(source.readByteArray(byteCount))).coAwait()
}
}
override fun flush() {}
//private val timeout = Timeout()
override fun timeout(): Timeout =
Timeout.NONE //timeout
override fun close() {
writeStream.end()
}
}
fun WriteStream.toSink(): Sink =
VertxBufferWriteStreamSink(this)
fun WriteStream.toBufferedSink(): Sink =
toSink().buffer()
© 2015 - 2025 Weber Informatics LLC | Privacy Policy