readAtMostTo

abstract fun readAtMostTo(sink: Buffer, byteCount: Long): Long(source)

Removes at least 1, and up to byteCount bytes from this source and appends them to sink. Returns the number of bytes read, or -1 if this source is exhausted.

Parameters

sink

the destination to write the data from this source.

byteCount

the number of bytes to read.

Throws

when the source is closed.

Samples

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

fun main() { 
   //sampleStart 
   val source = Buffer().also { it.write(byteArrayOf(1, 2, 3, 4, 5, 6)) }
val sink = Buffer()

val bytesRead = source.readAtMostTo(sink, 10) // read at most 10 bytes
assertEquals(6, bytesRead)
assertContentEquals(byteArrayOf(1, 2, 3, 4, 5, 6), sink.readByteArray()) 
   //sampleEnd
}