saket
okio.Source
ByteReadChannel
Aleksei Tirman [JB]
fun ByteReadChannel.toOkioSource(context: CoroutineContext = EmptyCoroutineContext): okio.Source { val channel = this return object : okio.Source { override fun close() { channel.cancel() } override fun read(sink: Buffer, byteCount: Long): Long { val buffer = ByteBuffer.allocateDirect(4096) val read = runBlocking(context) { channel.readAvailable(buffer) } buffer.flip() sink.write(buffer) return read.toLong() } override fun timeout(): Timeout { return Timeout() } } }
runBlocking
A modern programming language that makes developers happier.