write

fun OutputStream.write(source: ByteArray, sourceOffset: Int = 0, kapacity: Kapacity)

Writes up to the specified kapacity of bytes from the source array to this output stream.

This function blocks until the bytes are written or an exception is thrown.

  • Safe Bounds: The actual number of bytes written is safely clamped to prevent IndexOutOfBoundsException. The length will be the minimum of: the requested kapacity or the available data in the source array accounting for the sourceOffset.

Parameters

source

The data to write.

sourceOffset

The start offset in the source array from which to begin reading. Defaults to 0.

kapacity

The maximum number of bytes to write to the stream.

Throws

If an I/O error occurs.

fun Buffer.write(source: ByteArray, startIndex: Int = 0, kapacity: Kapacity)

Appends the specified kapacity of bytes from the source array into this buffer.

Warning on Bounds: Because primitive arrays are strictly indexed by Int, writing 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.

Parameters

source

The primitive array containing the data to write.

startIndex

The index in the source array to begin reading from. Defaults to 0.

kapacity

The amount of data to write into this buffer.


fun Buffer.write(source: RawSource, kapacity: Kapacity)

Appends exactly the specified kapacity of bytes from the source into this buffer.

Parameters

source

The source to read the bytes from.

kapacity

The exact amount of data to transfer into this buffer.

Throws

EOFException

if the source is exhausted before the requested capacity is written.