copyInto
fun copyInto(destination: ByteArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size)(source)
Copies a subsequence starting at startIndex and ending at endIndex of a byte sequence wrapped by this byte string and writes it into destination array starting at destinationOffset offset.
Parameters
destination
the array to copy data into.
destinationOffset
the offset starting from which data copy should be written to destination.
startIndex
the start index (inclusive) of a subsequence to copy, 0
by default.
endIndex
the end index (exclusive) of a subsequence to copy, size be default.
Throws
when the subrange doesn't fit into the destination array starting at the specified destinationOffset, or when that index is out of the destination array indices range.
when startIndex > endIndex
.
Samples
import kotlinx.io.bytestring.*
import kotlin.test.*
fun main() {
//sampleStart
val string = ByteString(1, 2, 3, 4, 5)
val array = ByteArray(10)
string.copyInto(array, destinationOffset = 3, startIndex = 1, endIndex = 4)
assertContentEquals(byteArrayOf(0, 0, 0, 2, 3, 4, 0, 0, 0, 0), array)
//sampleEnd
}