readKapacity
fun InputStream.readKapacity(destination: ByteArray, destinationOffset: Int = 0, kapacity: Kapacity): Kapacity
Reads up to the specified kapacity of bytes from this input stream into the given destination array, returning the result as a Kapacity instance.
Like its primitive counterpart, this function safely limits the read length to the available space in the destination array to prevent buffer overflows.
Return
The total number of bytes read wrapped in a Kapacity instance, or Kapacity.INVALID if the end of the stream has been reached.
Parameters
destination
The byte array to which data is written.
destinationOffset
The starting offset in the destination array where the data will be written. Defaults to 0.
kapacity
The maximum number of bytes to read from the stream.
Throws
If destinationOffset is outside the bounds of the destination array, or if kapacity represents a negative value.