transferFrom

Reads and exhausts bytes from input into this buffer. Stops reading data on input exhaustion.

Parameters

input

the stream to read data from.

Samples

import kotlinx.io.*
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.nio.ByteBuffer
import java.util.zip.GZIPInputStream
import java.util.zip.GZIPOutputStream
import kotlin.test.*

fun main() { 
   //sampleStart 
   val buffer = Buffer()
buffer.writeString("hello")

val outputStream = ByteArrayOutputStream()
buffer.readTo(outputStream)

assertTrue(buffer.exhausted())

val inputStream = ByteArrayInputStream(outputStream.toByteArray())
buffer.transferFrom(inputStream)

assertEquals("hello", buffer.readString()) 
   //sampleEnd
}

Reads all data from source into this buffer.

Samples

import kotlinx.io.*
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.nio.ByteBuffer
import java.util.zip.GZIPInputStream
import java.util.zip.GZIPOutputStream
import kotlin.test.*

fun main() { 
   //sampleStart 
   val buffer = Buffer()
val nioBuffer = ByteBuffer.allocate(32)

nioBuffer.put("hello".encodeToByteArray())
nioBuffer.position(0)
nioBuffer.limit(5)
buffer.transferFrom(nioBuffer)

assertEquals("hello", buffer.readString())
assertEquals(5, nioBuffer.position()) 
   //sampleEnd
}