readAtMostTo

fun Buffer.readAtMostTo(sink: Buffer, kapacity: Kapacity): Kapacity

Removes up to the specified kapacity of bytes from this buffer and appends them to the sink.

Return

A Kapacity representing the exact number of bytes that were successfully read and transferred.

Parameters

sink

The destination buffer to write the bytes into.

kapacity

The maximum amount of data to read.


fun Buffer.readAtMostTo(sink: ByteArray, startIndex: Int = 0, kapacity: Kapacity): Kapacity

Removes up to the specified kapacity of bytes from this buffer and writes them into the provided sink array.

Warning on Bounds: Because primitive arrays are strictly indexed by Int, reading operations are safely bounded to Int.MAX_VALUE- 8 (approximately 2.14 GB). The target end index is safely clamped to prevent IndexOutOfBoundsException if the calculated boundary exceeds the array's physical size.

Return

A Kapacity representing the exact number of bytes that were successfully read into the array.

Parameters

sink

The destination primitive array.

startIndex

The index in the sink array to begin writing the data. Defaults to 0.

kapacity

The maximum amount of data to read from this buffer.