copyTo
Copies bytes from this buffer's subrange starting at startIndex and ending at endIndex, to out buffer. This method does not consume data from the buffer.
Parameters
out
the destination buffer to copy data into.
startIndex
the index (inclusive) of the first byte of data in this buffer to copy, 0 by default.
endIndex
the index (exclusive) of the last byte of data in this buffer to copy, buffer.size
by default.
Throws
when startIndex or endIndex is out of this buffer bounds ([0..buffer.size)
).
when startIndex > endIndex
.
Samples
import kotlinx.io.*
import kotlin.test.*
fun main() {
//sampleStart
val buffer = Buffer()
buffer.writeString("some string")
val copy = Buffer()
copy.writeString("sub")
buffer.copyTo(copy, startIndex = 5)
assertEquals("some string", buffer.readString())
assertEquals("substring", copy.readString())
//sampleEnd
}