readTo

abstract fun readTo(sink: RawSink, byteCount: Long)(source)

Removes exactly byteCount bytes from this source and writes them to sink.

Parameters

sink

the sink to which data will be written from this source.

byteCount

the number of bytes that should be written into sink

Throws

when the requested number of bytes cannot be read.

when the source or sink is closed.

when some I/O error occurs.

Samples

import kotlinx.io.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   val sink = Buffer()
val source = Buffer().also { it.writeInt(0x01020304) }

source.readTo(sink, 3)
assertContentEquals(byteArrayOf(1, 2, 3), sink.readByteArray())
assertContentEquals(byteArrayOf(4), source.readByteArray()) 
   //sampleEnd
}