ByteString
Wraps a copy of data subarray starting at startIndex and ending at endIndex into a byte string.
Parameters
data
the array whose subarray should be copied and wrapped into a byte string.
startIndex
the start index (inclusive) of a subarray to copy, 0
by default.
endIndex
the end index (exclusive) of a subarray to copy, data.size
be default.
Throws
when startIndex or endIndex is out of range of data array indices.
when startIndex > endIndex
.
Samples
import kotlinx.io.bytestring.*
import kotlin.test.*
fun main() {
//sampleStart
val array = byteArrayOf(1, 2, 3)
val byteStringFromArray = ByteString(array)
array[1] = -1
// The modification of the source array won't affect the content of the string.
assertContentEquals(byteArrayOf(1, 2, 3), byteStringFromArray.toByteArray())
val largeArray = byteArrayOf(1, 2, 3, 4 /*, ... */)
val byteStringFromSubarray = ByteString(largeArray, startIndex = 1, endIndex = 3)
assertContentEquals(byteArrayOf(2, 3), byteStringFromSubarray.toByteArray())
//sampleEnd
}