putByteString

Writes string into this ByteBuffer starting from the current position.

Upon successfully execution ByteBuffer.position will advance by the length of string.

Throws

when this buffer is read-only

when string can't fit into remaining space of this buffer

Samples

import kotlinx.io.bytestring.*
import java.nio.ByteBuffer
import java.nio.ReadOnlyBufferException
import kotlin.test.*

fun main() { 
   //sampleStart 
   val buffer = ByteBuffer.allocate(32)
val byteString = ByteString(0x66, 0xdb.toByte(), 0x11, 0x50)

// Putting a ByteString into a buffer will advance its position
buffer.putByteString(byteString)
assertEquals(4, buffer.position())

buffer.flip()
assertEquals(1725632848, buffer.getInt()) 
   //sampleEnd
}

Writes string into this ByteBuffer starting from position at.

This function does not update ByteBuffer.position.

Throws

when this buffer is read-only

Samples

import kotlinx.io.bytestring.*
import java.nio.ByteBuffer
import java.nio.ReadOnlyBufferException
import kotlin.test.*

fun main() { 
   //sampleStart 
   val buffer = ByteBuffer.allocate(8)
val byteString = ByteString(0x78, 0x5e)

// Putting a ByteString into a buffer using an absolute offset
// won't change buffer's position.
buffer.putByteString(at = 3, string = byteString)
assertEquals(0, buffer.position())
assertEquals(8, buffer.remaining())

assertEquals(0x000000785e000000L, buffer.getLong()) 
   //sampleEnd
}