transferTo

open override fun transferTo(sink: RawSink): Long(source)

Removes all bytes from this source, writes them to sink, and returns the total number of bytes written to sink.

Return 0 if this source is exhausted.

Parameters

sink

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

Throws

when the source or sink is closed.

when some I/O error occurs.

Samples

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

fun main() { 
   //sampleStart 
   val src: Source = Buffer().also { it.writeString("Some data to transfer") }
val dst = Buffer().also { it.writeString("Transferred: ") }

src.transferTo(dst)

assertTrue(src.exhausted())
assertEquals("Transferred: Some data to transfer", dst.readString()) 
   //sampleEnd
}