IoBuffer
A read-write facade to actual buffer of fixed size. Multiple views could share the same actual buffer. Concurrent unsafe. The only concurrent-safe operation is release. In most cases ByteReadPacket and BytePacketBuilder should be used instead.
A read-write facade to actual buffer of fixed size. Multiple views could share the same actual buffer.
Constructors
Types
Functions
Close input including the underlying source. All pending bytes will be discarded. It is not recommended to invoke it with read operations in-progress concurrently.
Discard at most n bytes
Copy available bytes to the specified buffer but keep them available. The underlying implementation could trigger bytes population from the underlying source and block until any bytes available.
Try to copy at least min but up to max bytes to the specified destination buffer from this input skipping offset bytes. If there are not enough bytes available to provide min bytes after skipping offset bytes then it will trigger the underlying source reading first and after that will simply copy available bytes even if EOF encountered so min is not a requirement but a desired number of bytes. It is safe to specify max greater than the destination free space. min
shouldn't be bigger than the destination free space. This function could trigger the underlying source reading that may lead to blocking I/O. It is allowed to specify too big offset so in this case this function will always return 0
after prefetching all underlying bytes but note that it may lead to significant memory consumption. This function usually copy more bytes than min (unless max = min
) but it is not guaranteed. When 0
is returned with offset = 0
then it makes sense to check endOfInput.
Copy available bytes to the specified buffer but keep them available. If the underlying implementation could trigger bytes population from the underlying source and block until any bytes available
Copy at least min but up to max bytes to the specified destination buffer from this input skipping offset bytes. If there are not enough bytes available to provide min bytes then it fails with an exception. It is safe to specify max > destination.writeRemaining
but min
shouldn't be bigger than the destination free space. This function could trigger the underlying source reading that may lead to blocking I/O. It is safe to specify too big offset but only if min = 0
, fails otherwise. This function usually copy more bytes than min (unless max = min
).
Copy available bytes to the specified buffer but keep them available. If the underlying implementation could trigger bytes population from the underlying source and block until any bytes available
Copy at least min but up to max bytes to the specified destination buffer from this input skipping offset bytes. If there are not enough bytes available to provide min bytes then it fails with an exception. It is safe to specify max > destination.writeRemaining
but min
shouldn't be bigger than the destination free space. This function could trigger the underlying source reading that may lead to blocking I/O. It is safe to specify too big offset but only if min = 0
, fails otherwise. This function usually copy more bytes than min (unless max = min
).
Apply block function on a ByteBuffer of readable bytes. The block function should return number of consumed bytes.
Apply block to a native pointer for reading from the buffer. Lambda should return number of bytes were read.
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 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 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.
Reserve startGap bytes in the beginning. May move readPosition and writePosition if no bytes available for reading.
Reserve startGap bytes in the beginning. May move readPosition and writePosition if no bytes available for reading.
Clear buffer's state: read/write positions, gaps and so on. Byte content is not cleaned-up.
Clear buffer's state: read/write positions, gaps and so on. Byte content is not cleaned-up.
Clear buffer's state: read/write positions, gaps and so on. Byte content is not cleaned-up.
Marks the whole buffer available for read and no for write
Marks the whole buffer available for read and no for write
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.
Marks all capacity writable except the start gap reserved before. The end gap reservation is discarded.
Marks all capacity writable except the start gap reserved before. The end gap reservation is discarded.
Reset read/write position to original's content pos/limit. May not work due to slicing.
Rewind readPosition backward to make count bytes available for reading again.
Rewind readPosition backward to make count bytes available for reading again.
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.
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.
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.
Read the next unsigned byte or return -1
if no more bytes available for reading. The returned byte is marked as consumed.
Read the next unsigned byte or return -1
if no more bytes available for reading. The returned byte is marked as consumed.
Apply block function on a ByteBuffer of the free space. The block function should return number of written bytes.
Apply block to a native pointer for writing to the buffer. Lambda should return number of bytes were written.
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.
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.
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.
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.
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.
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.
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.
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.
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.