IoBuffer
expect class IoBuffer : Input, Output, ChunkBuffer
Deprecated: Use Memory, Input or Output instead.
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.
Constructors
IoBuffer(memory: Memory, origin: ChunkBuffer?) IoBuffer(external: ByteBuffer) |
Properties
var |
|
val endOfInput: Boolean It is |
Inherited Properties
abstract val endOfInput: Boolean It is |
|
var next: ChunkBuffer? Reference to next buffer view. Useful to chain multiple views. |
|
var origin: ChunkBuffer? Reference to an origin buffer view this was copied from |
|
val referenceCount: Int |
Functions
fun fun fun fun |
|
fun |
|
fun |
|
fun |
|
fun close(): Unit |
|
fun duplicate(): IoBuffer Create a new Buffer instance pointing to the same memory and having the same positions. |
|
fun flush(): Unit |
|
fun |
|
fun |
|
fun Creates a new view to the same actual buffer with independent read and write positions and gaps |
|
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 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 |
|
Push back n bytes: only possible if there were at least n bytes read before this operation. |
|
fun |
|
fun fun fun fun |
|
fun readDirect(block: (ByteBuffer) -> Unit): Int Apply block function on a ByteBuffer of readable bytes. The block function should return number of consumed bytes. |
|
fun |
|
fun |
|
fun fun fun fun |
|
fun |
|
fun |
|
fun |
|
fun |
|
fun release(pool: ObjectPool<IoBuffer>): Unit |
|
fun resetFromContentToWrite(child: ByteBuffer): Unit Reset read/write position to original’s content pos/limit. May not work due to slicing. |
|
fun toString(): String |
|
fun tryPeek(): Int |
|
fun |
|
fun writeDirect(size: Int, block: (ByteBuffer) -> Unit): Int Apply block function on a ByteBuffer of the free space. The block function should return number of written bytes. |
|
fun fun fun fun |
|
Inherited Functions
abstract fun append( |
|
fun cleanNext(): ChunkBuffer? |
|
Discard at most n bytes |
|
open fun duplicate(): ChunkBuffer Create a new Buffer instance pointing to the same memory and having the same positions. |
|
abstract fun peekTo( 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.
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. |
|
open fun open fun open fun open fun |
|
abstract fun readByte(): Byte Read the next upcoming byte |
|
open fun |
|
open fun |
|
open fun open fun open fun open fun |
|
open fun |
|
open fun |
|
open fun |
|
open fun release(pool: ObjectPool<ChunkBuffer>): Unit |
|
fun reset(): Unit Clear buffer’s state: read/write positions, gaps and so on. Byte content is not cleaned-up. |
|
abstract fun tryPeek(): Int |
|
open fun open fun open fun open fun |
|
Companion Object Properties
val Empty: IoBuffer The empty buffer singleton: it has zero capacity for read and write. |
|
val EmptyPool: ObjectPool<IoBuffer> A pool that always returns IoBuffer.Empty |
|
val NoPool: ObjectPool<IoBuffer> Pool that always instantiates new buffers instead of reusing it |
|
val Pool: ObjectPool<IoBuffer> The default buffer pool |
|
val ReservedSize: Int Number of bytes usually reserved in the end of chunk when several instances of ChunkBuffer are connected into a chain (usually inside of ByteReadPacket or BytePacketBuilder) |
Extension Properties
For streaming input it should be Input.endOfInput instead. |
|
For streaming input there is no reliable way to detect it without triggering bytes population from the underlying source. Consider using Input.endOfInput or use ByteReadPacket instead. |
Extension Functions
fun Output.afterHeadWrite(current: ChunkBuffer): Unit |
|
fun Buffer. fun Buffer. fun Output.append( |
|
fun Input.asStream(): InputStream Convert io.ktor.utils.io Input to java InputStream |
|
fun Input.completeReadHead(current: ChunkBuffer): Unit |
|
Copy all bytes to the output. Depending on actual input and output implementation it could be zero-copy or copy byte per byte. All regular types such as ByteReadPacket, BytePacketBuilder, AbstractInput and AbstractOutput are always optimized so no bytes will be copied. |
|
Discard all remaining bytes. |
|
Discard exactly n bytes or fail if not enough bytes in the input to be discarded. |
|
Discards bytes until delimiter occurred |
|
Discards bytes until of of the specified delimiters delimiter1 or delimiter2 occurred |
|
fun Input. fun Input. 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 simply return number of available bytes with no exception so the returned value need
to be checked.
It is safe to specify |
|
fun Input.prepareReadFirstHead(minSize: Int): ChunkBuffer? |
|
fun Input.prepareReadNextHead( |
|
fun Output.prepareWriteHead( |
|
Push back n bytes: only possible if there were at least n bytes read before this operation. |
|
Apply block of code with buffer’s memory providing read range indices. The returned value of block lambda should return number of bytes to be marked as consumed. No read/write functions on this buffer should be called inside of block otherwise an undefined behaviour may occur including data damage. |
|
fun IoBuffer. fun Buffer.readAvailable( 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. |
|
fun Input. fun Input. fun Input. |
|
Reads all remaining bytes from the input |
|
Reads at least min but no more than max bytes from the input to a new byte array |
|
fun Buffer. |
|
fun IoBuffer. fun Buffer.readFully( Read from this buffer to the destination array to offset and length bytes. fun Buffer.readFully(destination: ByteBuffer): Unit Read buffer’s content to the destination buffer moving it’s position. |
|
fun Input. fun Input. fun Input. |
|
fun Buffer. fun Input. fun Input. Reads at most max characters decoding bytes with specified decoder. Extra character bytes will remain unconsumed fun Input.readText( Reads at most max characters decoding bytes with specified charset. Extra character bytes will remain unconsumed |
|
Read exactly n characters interpreting bytes in the specified charset. |
|
Read exactly the specified number of bytes interpreting bytes in the specified charset (optional, UTF-8 by default). Read exactly bytesCount interpreting bytes in the specified charset (optional, UTF-8 by default). |
|
Read exactly charactersCount characters interpreting bytes in the specified charset. |
|
fun IoBuffer. |
|
fun IoBuffer. |
|
fun IoBuffer. |
|
fun IoBuffer. |
|
Read a string line considering optionally specified estimate but up to optional limit characters length
(does fail once limit exceeded) or return |
|
fun Input.readUTF8LineTo( Read UTF-8 line and append all line characters to out except line endings. Does support CR, LF and CR+LF |
|
Reads UTF-8 characters until one of the specified delimiters found, limit exceeded or end of stream encountered |
|
fun Input.readUTF8UntilDelimiterTo( fun Input.readUTF8UntilDelimiterTo( Reads UTF-8 characters to out buffer until one of the specified delimiters found, limit exceeded or end of stream encountered fun Input. |
|
fun Input.readUntilDelimiter( Copies to dst array at offset at most length bytes or until the specified delimiter occurred. Copies to dst output until the specified delimiter occurred. |
|
fun Input.readUntilDelimiters( Copies to dst array at offset at most length bytes or until one of the specified delimiters delimiter1 or delimiter2 occurred. Copies to dst output until one of the specified delimiters delimiter1 or delimiter2 occurred. |
|
fun IoBuffer.release(pool: ObjectPool<IoBuffer>): Unit releases buffer view and returns it to the pool if there are no more usages. Based on simple ref-counting so it is very fragile. |
|
fun ChunkBuffer.remainingAll(): Long Summarize remainings of all elements of the chain |
|
Invoke block function for every chunk until end of input or block function return |
|
Invoke block function for every chunk until end of input or block function return zero block function returns number of bytes required to read next primitive and shouldn’t require too many bytes at once otherwise it could fail with an exception. It is not guaranteed that every chunk will have fixed size but it will be always at least requested bytes length. block function should never release provided buffer and should not write to it otherwise an undefined behaviour could be observed |
|
Peek the next unsigned byte or return |
|
Apply block of code with buffer’s memory providing write range indices. The returned value of block lambda should return number of bytes were written. o read/write functions on this buffer should be called inside of block otherwise an undefined behaviour may occur including data damage. |
|
fun Buffer. |
|
fun IoBuffer. fun Output.writeFully( fun Buffer.writeFully( Write the whole source array range staring at offset and having the specified bytes length. Write all readable bytes from src to this buffer. Fails if not enough space available to write all bytes. |
|
fun Output.writePacket(packet: ByteReadPacket): Unit |
|
fun Output. Writes text characters in range [fromIndex .. toIndex) with the specified encoder fun Output.writeText( fun Output.writeText( Writes text characters in range [fromIndex .. toIndex) with the specified charset |
|
Write an unsigned byte or fail if not enough space available for writing. |
|
Write an unsigned integer or fail if not enough space available for writing. The numeric value is encoded in the network order (Big Endian). |
|
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). |
|
Append number of chunks invoking block function while the returned value is true. Depending on the output underlying implementation it could invoke block function with the same buffer several times however it is guaranteed that it is always non-empty. |
|
Append number of chunks invoking block function while the returned value is positive. If returned value is positive then it will be invoked again with a buffer having at least requested number of bytes space (could be the same buffer as before if it complies to the restriction). |