Input

expect interface Input : Closeable

Usually shouldn't be implemented directly. Inherit AbstractInput instead.

actual interface Input : Closeable

Shouldn't be implemented directly. Inherit AbstractInput instead.

actual interface Input : Closeable

Functions

Link copied to clipboard
expect abstract override fun close()

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.

actual abstract override fun close()
actual abstract override fun close()
Link copied to clipboard
expect abstract fun discard(n: Long): Long

Discard at most n bytes

actual abstract fun discard(n: Long): Long
actual abstract fun discard(n: Long): Long
Link copied to clipboard
expect open fun peekTo(buffer: IoBuffer): Int

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.

expect abstract fun peekTo(destination: Memory, destinationOffset: Long, offset: Long = 0, min: Long = 1, max: Long = Long.MAX_VALUE): Long

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.

actual open fun peekTo(buffer: IoBuffer): Int

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

actual abstract fun peekTo(destination: Memory, destinationOffset: Long, offset: Long = 0, min: Long = 1, max: Long = Long.MAX_VALUE): Long

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).

actual open fun peekTo(buffer: IoBuffer): Int

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

actual abstract fun peekTo(destination: Memory, destinationOffset: Long, offset: Long = 0, min: Long = 1, max: Long = Long.MAX_VALUE): Long

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).

Link copied to clipboard
expect open fun readAvailable(dst: IoBuffer, length: Int): Int
expect open fun readAvailable(dst: ByteArray, offset: Int, length: Int): Int
expect open fun readAvailable(dst: DoubleArray, offset: Int, length: Int): Int
expect open fun readAvailable(dst: FloatArray, offset: Int, length: Int): Int
expect open fun readAvailable(dst: IntArray, offset: Int, length: Int): Int
expect open fun readAvailable(dst: LongArray, offset: Int, length: Int): Int
expect open fun readAvailable(dst: ShortArray, offset: Int, length: Int): Int
actual open fun readAvailable(dst: IoBuffer, length: Int): Int
open fun readAvailable(dst: ByteBuffer, length: Int = dst.remaining()): Int
actual open fun readAvailable(dst: ByteArray, offset: Int, length: Int): Int
actual open fun readAvailable(dst: DoubleArray, offset: Int, length: Int): Int
actual open fun readAvailable(dst: FloatArray, offset: Int, length: Int): Int
actual open fun readAvailable(dst: IntArray, offset: Int, length: Int): Int
actual open fun readAvailable(dst: LongArray, offset: Int, length: Int): Int
actual open fun readAvailable(dst: ShortArray, offset: Int, length: Int): Int
actual open fun readAvailable(dst: IoBuffer, length: Int): Int
open fun readAvailable(dst: <ERROR CLASS><<ERROR CLASS>>, offset: Int, length: Int): Int
open fun readAvailable(dst: <ERROR CLASS><<ERROR CLASS>>, offset: Long, length: Long): Long
actual open fun readAvailable(dst: ByteArray, offset: Int, length: Int): Int
actual open fun readAvailable(dst: DoubleArray, offset: Int, length: Int): Int
actual open fun readAvailable(dst: FloatArray, offset: Int, length: Int): Int
actual open fun readAvailable(dst: IntArray, offset: Int, length: Int): Int
actual open fun readAvailable(dst: LongArray, offset: Int, length: Int): Int
actual open fun readAvailable(dst: ShortArray, offset: Int, length: Int): Int
Link copied to clipboard
expect abstract fun readByte(): Byte

Read the next upcoming byte

actual abstract fun readByte(): Byte
actual abstract fun readByte(): Byte

Read the next upcoming byte

Link copied to clipboard
expect open fun readDouble(): Double
actual open fun readDouble(): Double
actual open fun readDouble(): Double
Link copied to clipboard
expect open fun readFloat(): Float
actual open fun readFloat(): Float
actual open fun readFloat(): Float
Link copied to clipboard
expect open fun readFully(dst: IoBuffer, length: Int)
expect open fun readFully(dst: ByteArray, offset: Int, length: Int)
expect open fun readFully(dst: DoubleArray, offset: Int, length: Int)
expect open fun readFully(dst: FloatArray, offset: Int, length: Int)
expect open fun readFully(dst: IntArray, offset: Int, length: Int)
expect open fun readFully(dst: LongArray, offset: Int, length: Int)
expect open fun readFully(dst: ShortArray, offset: Int, length: Int)
actual open fun readFully(dst: IoBuffer, length: Int)
open fun readFully(dst: ByteBuffer, length: Int = dst.remaining())
actual open fun readFully(dst: ByteArray, offset: Int, length: Int)
actual open fun readFully(dst: DoubleArray, offset: Int, length: Int)
actual open fun readFully(dst: FloatArray, offset: Int, length: Int)
actual open fun readFully(dst: IntArray, offset: Int, length: Int)
actual open fun readFully(dst: LongArray, offset: Int, length: Int)
actual open fun readFully(dst: ShortArray, offset: Int, length: Int)
actual open fun readFully(dst: IoBuffer, length: Int)
open fun readFully(dst: <ERROR CLASS><<ERROR CLASS>>, offset: Int, length: Int)
open fun readFully(dst: <ERROR CLASS><<ERROR CLASS>>, offset: Long, length: Long)
actual open fun readFully(dst: ByteArray, offset: Int, length: Int)
actual open fun readFully(dst: DoubleArray, offset: Int, length: Int)
actual open fun readFully(dst: FloatArray, offset: Int, length: Int)
actual open fun readFully(dst: IntArray, offset: Int, length: Int)
actual open fun readFully(dst: LongArray, offset: Int, length: Int)
actual open fun readFully(dst: ShortArray, offset: Int, length: Int)
Link copied to clipboard
expect open fun readInt(): Int
actual open fun readInt(): Int
actual open fun readInt(): Int
Link copied to clipboard
expect open fun readLong(): Long
actual open fun readLong(): Long
actual open fun readLong(): Long
Link copied to clipboard
expect open fun readShort(): Short
actual open fun readShort(): Short
actual open fun readShort(): Short
Link copied to clipboard
expect abstract fun tryPeek(): Int
actual abstract fun tryPeek(): Int
actual abstract fun tryPeek(): Int

Properties

Link copied to clipboard
expect abstract var byteOrder: ByteOrder
actual abstract var byteOrder: ByteOrder
actual abstract var byteOrder: ByteOrder
Link copied to clipboard
expect abstract val endOfInput: Boolean

It is true when it is known that no more bytes will be available. When it is false then this means that it is not known yet or there are available bytes. Please note that false value doesn't guarantee that there are available bytes so readByte() may fail.

actual abstract val endOfInput: Boolean

It is true when it is known that no more bytes will be available. When it is false then this means that it is not known yet or there are available bytes. Please note that false value doesn't guarantee that there are available bytes so readByte() may fail.

actual abstract val endOfInput: Boolean

It is true when it is known that no more bytes will be available. When it is false then this means that it is not known yet or there are available bytes. Please note that false value doesn't guarantee that there are available bytes so readByte() may fail.

Inheritors

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Extensions

Link copied to clipboard
fun Input.completeReadHead(current: IoBuffer)
fun Input.completeReadHead(current: ChunkBuffer)
Link copied to clipboard
fun Input.copyTo(output: Output): Long

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.

Link copied to clipboard
fun Input.discard(): Long

Discard all remaining bytes.

Link copied to clipboard
fun Input.discardExact(n: Long)
fun Input.discardExact(n: Int)

Discard exactly n bytes or fail if not enough bytes in the input to be discarded.

Link copied to clipboard
fun Input.discardUntilDelimiter(delimiter: Byte): Long

Discards bytes until delimiter occurred

Link copied to clipboard
fun Input.discardUntilDelimiters(delimiter1: Byte, delimiter2: Byte): Long

Discards bytes until of of the specified delimiters delimiter1 or delimiter2 occurred

Link copied to clipboard
inline fun Input.forEach(block: (Byte) -> Unit)

For every byte from this input invokes block function giving it as parameter.

Link copied to clipboard
val Input.isEmpty: Boolean

For streaming input it should be Input.endOfInput instead.

Link copied to clipboard
val Input.isNotEmpty: Boolean

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.

Link copied to clipboard
fun Input.peekCharUtf8(): Char
Link copied to clipboard
fun Input.peekTo(destination: IoBuffer, offset: Int = 0, min: Int = 1, max: Int = Int.MAX_VALUE): Int
fun Input.peekTo(destination: Buffer, offset: Int = 0, min: Int = 1, max: Int = Int.MAX_VALUE): Int

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 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 so in this case this function will always return 0. 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 Input.endOfInput.

Link copied to clipboard
fun Input.prepareReadFirstHead(minSize: Int): ChunkBuffer?
Link copied to clipboard
@JvmName(name = "prepareReadFirstHead")
fun Input.prepareReadFirstHeadOld(minSize: Int): IoBuffer?
Link copied to clipboard
fun Input.prepareReadNextHead(current: ChunkBuffer): ChunkBuffer?
Link copied to clipboard
@JvmName(name = "prepareReadNextHead")
fun Input.prepareReadNextHeadOld(current: IoBuffer): IoBuffer?
Link copied to clipboard
fun Input.readAvailable(dst: IoBuffer, size: Int = dst.writeRemaining): Int
fun Input.readAvailable(dst: ByteArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailable(dst: ShortArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailable(dst: IntArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailable(dst: LongArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailable(dst: FloatArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailable(dst: DoubleArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailable(dst: Buffer, length: Int = dst.writeRemaining): Int
fun Input.readAvailable(destination: Memory, destinationOffset: Int, length: Int): Int
fun Input.readAvailable(destination: Memory, destinationOffset: Long, length: Long): Long
fun Input.readAvailable(dst: ByteBuffer, length: Int = dst.remaining()): Int
fun Input.readAvailable(dst: <ERROR CLASS><<ERROR CLASS>>, offset: Int, length: Int): Int
fun Input.readAvailable(dst: <ERROR CLASS><<ERROR CLASS>>, offset: Long, length: Long): Long
Link copied to clipboard
fun Input.readAvailableLittleEndian(dst: UShortArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailableLittleEndian(dst: ShortArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailableLittleEndian(dst: UIntArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailableLittleEndian(dst: IntArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailableLittleEndian(dst: ULongArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailableLittleEndian(dst: LongArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailableLittleEndian(dst: FloatArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailableLittleEndian(dst: DoubleArray, offset: Int = 0, length: Int = dst.size - offset): Int
Link copied to clipboard
@JvmName(name = "readAvailable")
fun Input.readAvailableOld(dst: ByteArray, offset: Int = 0, length: Int = dst.size - offset): Int
@JvmName(name = "readAvailable")
fun Input.readAvailableOld(dst: ShortArray, offset: Int = 0, length: Int = dst.size - offset): Int
@JvmName(name = "readAvailable")
fun Input.readAvailableOld(dst: IntArray, offset: Int = 0, length: Int = dst.size - offset): Int
@JvmName(name = "readAvailable")
fun Input.readAvailableOld(dst: LongArray, offset: Int = 0, length: Int = dst.size - offset): Int
@JvmName(name = "readAvailable")
fun Input.readAvailableOld(dst: FloatArray, offset: Int = 0, length: Int = dst.size - offset): Int
@JvmName(name = "readAvailable")
fun Input.readAvailableOld(dst: DoubleArray, offset: Int = 0, length: Int = dst.size - offset): Int
Link copied to clipboard
fun Input.readBytes(n: Int): ByteArray

Reads exactly n bytes from the input or fails if not enough bytes available.

fun Input.readBytes(): ByteArray

Reads all remaining bytes from the input

Link copied to clipboard
fun Input.readBytesOf(min: Int = 0, max: Int = Int.MAX_VALUE): ByteArray

Reads at least min but no more than max bytes from the input to a new byte array

Link copied to clipboard
fun Input.readDouble(byteOrder: ByteOrder): Double
fun Input.readDouble(): Double
Link copied to clipboard
fun Input.readDoubleFallback(): Double
Link copied to clipboard
fun Input.readDoubleLittleEndian(): Double
Link copied to clipboard
fun Input.readFloat(byteOrder: ByteOrder): Float
fun Input.readFloat(): Float
Link copied to clipboard
fun Input.readFloatFallback(): Float
Link copied to clipboard
fun Input.readFloatLittleEndian(): Float
Link copied to clipboard
fun Input.readFully(dst: IoBuffer, size: Int = dst.writeRemaining)
fun Input.readFully(dst: ByteArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFully(dst: ShortArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFully(dst: IntArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFully(dst: LongArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFully(dst: FloatArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFully(dst: DoubleArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFully(dst: Buffer, length: Int = dst.writeRemaining)
fun Input.readFully(destination: Memory, destinationOffset: Int, length: Int)
fun Input.readFully(destination: Memory, destinationOffset: Long, length: Long)
inline fun Input.readFully(dst: UByteArray, offset: Int = 0, length: Int = dst.size - offset)
inline fun Input.readFully(dst: UShortArray, offset: Int = 0, length: Int = dst.size - offset)
inline fun Input.readFully(dst: UIntArray, offset: Int = 0, length: Int = dst.size - offset)
inline fun Input.readFully(dst: ULongArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFully(dst: ByteBuffer, length: Int = dst.remaining())
fun Input.readFully(dst: <ERROR CLASS><<ERROR CLASS>>, offset: Int, length: Int)
fun Input.readFully(dst: <ERROR CLASS><<ERROR CLASS>>, offset: Long, length: Long)
Link copied to clipboard
fun Input.readFullyLittleEndian(dst: UShortArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFullyLittleEndian(dst: ShortArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFullyLittleEndian(dst: UIntArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFullyLittleEndian(dst: IntArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFullyLittleEndian(dst: ULongArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFullyLittleEndian(dst: LongArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFullyLittleEndian(dst: FloatArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFullyLittleEndian(dst: DoubleArray, offset: Int = 0, length: Int = dst.size - offset)
Link copied to clipboard
@JvmName(name = "readFully")
fun Input.readFullyOld(dst: ByteArray, offset: Int = 0, length: Int = dst.size - offset)
@JvmName(name = "readFully")
fun Input.readFullyOld(dst: ShortArray, offset: Int = 0, length: Int = dst.size - offset)
@JvmName(name = "readFully")
fun Input.readFullyOld(dst: IntArray, offset: Int = 0, length: Int = dst.size - offset)
@JvmName(name = "readFully")
fun Input.readFullyOld(dst: LongArray, offset: Int = 0, length: Int = dst.size - offset)
@JvmName(name = "readFully")
fun Input.readFullyOld(dst: FloatArray, offset: Int = 0, length: Int = dst.size - offset)
@JvmName(name = "readFully")
fun Input.readFullyOld(dst: DoubleArray, offset: Int = 0, length: Int = dst.size - offset)
Link copied to clipboard
fun Input.readInt(byteOrder: ByteOrder): Int
fun Input.readInt(): Int
Link copied to clipboard
fun Input.readIntLittleEndian(): Int
Link copied to clipboard
fun Input.readLong(byteOrder: ByteOrder): Long
fun Input.readLong(): Long
Link copied to clipboard
fun Input.readLongLittleEndian(): Long
Link copied to clipboard
fun Input.readShort(byteOrder: ByteOrder): Short
fun Input.readShort(): Short
Link copied to clipboard
fun Input.readShortLittleEndian(): Short
Link copied to clipboard
fun Input.readText(out: Appendable, decoder: CharsetDecoder, max: Int = Int.MAX_VALUE): Int
fun Input.readText(decoder: CharsetDecoder, max: Int = Int.MAX_VALUE): String

Reads at most max characters decoding bytes with specified decoder. Extra character bytes will remain unconsumed

fun Input.readText(out: Appendable, charset: Charset = Charsets.UTF_8, max: Int = Int.MAX_VALUE): Int
fun Input.readText(charset: Charset = Charsets.UTF_8, max: Int = Int.MAX_VALUE): String

Reads at most max characters decoding bytes with specified charset. Extra character bytes will remain unconsumed

Link copied to clipboard
fun Input.readTextExact(charset: Charset = Charsets.UTF_8, n: Int): String

Read exactly n characters interpreting bytes in the specified charset.

Link copied to clipboard
fun Input.readTextExactBytes(charset: Charset = Charsets.UTF_8, bytes: Int): String

Read exactly the specified number of bytes interpreting bytes in the specified charset (optional, UTF-8 by default).

fun Input.readTextExactBytes(bytesCount: Int, charset: Charset = Charsets.UTF_8): String

Read exactly bytesCount interpreting bytes in the specified charset (optional, UTF-8 by default).

Link copied to clipboard
fun Input.readTextExactCharacters(charactersCount: Int, charset: Charset = Charsets.UTF_8): String

Read exactly charactersCount characters interpreting bytes in the specified charset.

Link copied to clipboard
inline fun Input.readUByte(): UByte
Link copied to clipboard
inline fun Input.readUInt(): UInt
Link copied to clipboard
inline fun Input.readULong(): ULong
Link copied to clipboard
fun Input.readUntilDelimiter(delimiter: Byte, dst: ByteArray, offset: Int = 0, length: Int = dst.size): Int

Copies to dst array at offset at most length bytes or until the specified delimiter occurred.

fun Input.readUntilDelimiter(delimiter: Byte, dst: Output): Long

Copies to dst output until the specified delimiter occurred.

Link copied to clipboard
fun Input.readUntilDelimiters(delimiter1: Byte, delimiter2: Byte, dst: ByteArray, offset: Int = 0, length: Int = dst.size): Int

Copies to dst array at offset at most length bytes or until one of the specified delimiters delimiter1 or delimiter2 occurred.

fun Input.readUntilDelimiters(delimiter1: Byte, delimiter2: Byte, dst: Output): Long

Copies to dst output until one of the specified delimiters delimiter1 or delimiter2 occurred.

Link copied to clipboard
inline fun Input.readUShort(): UShort
Link copied to clipboard
fun Input.readUTF8Line(estimate: Int = 16, limit: Int = Int.MAX_VALUE): String?

Read a string line considering optionally specified estimate but up to optional limit characters length (does fail once limit exceeded) or return null if the packet is empty

Link copied to clipboard
fun Input.readUTF8LineTo(out: Appendable, limit: Int): Boolean

Reads UTF-8 line and append all line characters to out except line endings. Supports CR, LF and CR+LF

Link copied to clipboard
fun Input.readUTF8UntilDelimiter(delimiters: String, limit: Int = Int.MAX_VALUE): String

Reads UTF-8 characters until one of the specified delimiters found, limit exceeded or end of stream encountered

Link copied to clipboard
fun Input.readUTF8UntilDelimiterTo(out: Appendable, delimiters: String, limit: Int = Int.MAX_VALUE): Int
fun Input.readUTF8UntilDelimiterTo(out: Output, delimiters: String, limit: Int = Int.MAX_VALUE): Int

Reads UTF-8 characters to out buffer until one of the specified delimiters found, limit exceeded or end of stream encountered

fun Input.readUTF8UntilDelimiterTo(out: BytePacketBuilderBase, delimiters: String, limit: Int = Int.MAX_VALUE): Int
Link copied to clipboard
inline fun Input.takeWhile(block: (Buffer) -> Boolean)

Invoke block function for every chunk until end of input or block function return falseblock function returns true to request more chunks or false to stop loop

Link copied to clipboard
inline fun Input.takeWhileSize(initialSize: Int = 1, block: (Buffer) -> Int)

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