ktor-utils / io.ktor.util / java.nio.ByteBuffer

Extensions for java.nio.ByteBuffer

copy

fun ByteBuffer.copy(size: Int = remaining()): ByteBuffer

Moves all bytes in this buffer to a newly created buffer with the optionally specified size

fun ByteBuffer.copy(pool: ObjectPool<ByteBuffer>, size: Int = remaining()): ByteBuffer

Moves all bytes in this buffer to a newly created buffer with the optionally specified size by allocating it from the given pool

decodeString

fun ByteBuffer.decodeString(charset: Charset = Charsets.UTF_8): String

Decodes a string from this buffer with the specified charset

moveTo

fun ByteBuffer.moveTo(destination: ByteBuffer, limit: Int = Int.MAX_VALUE): Int

Moves bytes from this buffer to the destination buffer

moveToByteArray

fun ByteBuffer.moveToByteArray(): ByteArray

Moves bytes from this buffer into newly created ByteArray and returns it