ChunkBuffer
Deprecated
We're migrating to the new kotlinx-io library. This declaration is deprecated and will be removed in Ktor 4.0.0 If you have any problems with migration, please contact us in https://youtrack.jetbrains.com/issue/KTOR-6030/Migrate-to-new-kotlinx.io-library
Properties
Write position limit. No bytes could be written ahead of this limit. When the limit is less than the capacity then this means that there are reserved bytes in the end (endGap). Such a reserved space in the end could be used to write size, hash and so on. Also it is useful when several buffers are connected into a chain and some primitive value (e.g. kotlin.Int
) is separated into two chunks so bytes from the second chain could be copied to the reserved space of the first chunk and then the whole value could be read at once.
Reference to next buffer view. Useful to chain multiple views.
Reference to an origin buffer view this was copied from
Current read position. It is always non-negative and will never run ahead of the writePosition. It is usually greater or equal to startGap reservation. This position is affected by discard, rewind, resetForRead, resetForWrite, reserveStartGap and reserveEndGap.
Number of bytes available for reading.
Current write position. It is always non-negative and will never run ahead of the limit. It is always greater or equal to the readPosition.
Size of the free space available for writing in bytes.
Functions
Discard count readable bytes.
Create a new Buffer instance pointing to the same memory and having the same positions.
Read available for read bytes to the destination array range starting at array offset and length bytes. If less than length bytes available then less bytes will be copied and the corresponding number will be returned as result.
Read available for read bytes to the destination array range starting at array offset and length elements. If less than length elements available then less elements will be copied and the corresponding number will be returned as result (possibly zero).
Read the next byte or fail with EOFException if it's not available. The returned byte is marked as consumed.
Apply block function on a ByteBuffer of readable bytes. The block function should return number of consumed bytes.
Read a floating point number or fail if not enough bytes available for reading. The numeric value is decoded in the network order (Big Endian).
Read from this buffer to the destination array to offset and length bytes.
Read from this buffer to the destination array to offset and length bytes. Numeric values are interpreted in the network byte order (Big Endian).
Read buffer's content to the destination buffer moving its position.
Read an unsigned short integer or fail if not enough bytes available for reading. The numeric value is decoded in the network order (Big Endian).
Reserve endGap bytes in the end. Could move readPosition and writePosition to reserve space but only when no bytes were written or all written bytes are marked as consumed (were read or discarded).
Reserve startGap bytes in the beginning. May move readPosition and writePosition if no bytes available for reading.
Marks the whole buffer available for read and no for write
Marks all capacity writable except the start gap reserved before. The end gap reservation is discarded.
Rewind readPosition backward to make count bytes available for reading again.
Peek the next unsigned byte or return -1
if no more bytes available for reading. No bytes will be marked as consumed in any case.
Read the next unsigned byte or return -1
if no more bytes available for reading. The returned byte is marked as consumed.
Write a byte value at writePosition (incremented when written successfully).
Apply block function on a ByteBuffer of the free space. The block function should return number of written bytes.
Write a floating point number or fail if not enough space available for writing. The numeric value is encoded in the network order (Big Endian).
Write a floating point number or fail if not enough space available for writing. The numeric value is encoded in the network order (Big Endian).
Write all readable bytes from src to this buffer. Fails if not enough space available to write all bytes.
Write at most length readable bytes from src to this buffer. Fails if not enough space available to write all bytes.
Write the whole source array range staring at offset and having the specified items length. Numeric values are interpreted in the network byte order (Big Endian).
Write source buffer content moving its position.
Write a short integer or fail if not enough space available for writing. The numeric value is encoded in the network order (Big Endian).
Write an unsigned byte or fail if not enough space available for writing.
Write an unsigned long integer or fail if not enough space available for writing. The numeric value is encoded in the network order (Big Endian).
Write an unsigned short integer or fail if not enough space available for writing. The numeric value is encoded in the network order (Big Endian).