Package io.ktor.utils.io

Types

ByteChannel
Link copied to clipboard
common
interface ByteChannel : ByteReadChannel, ByteWriteChannel
Channel for asynchronous reading and writing of sequences of bytes.
ByteChannelSequentialBase
Link copied to clipboard
common
Sequential (non-concurrent) byte channel implementation
ByteChannelSequentialJVM
Link copied to clipboard
class ByteChannelSequentialJVM(initial: IoBuffer, autoFlush: Boolean) : ByteChannelSequentialBase
ByteReadChannel
Link copied to clipboard
common
interface ByteReadChannel
Channel for asynchronous reading of sequences of bytes.
interface ByteReadChannel
Channel for asynchronous reading of sequences of bytes.
posix
interface ByteReadChannel
Channel for asynchronous reading of sequences of bytes.
ByteWriteChannel
Link copied to clipboard
common
interface ByteWriteChannel
Channel for asynchronous writing of sequences of bytes.
interface ByteWriteChannel
Channel for asynchronous writing of sequences of bytes.
posix
interface ByteWriteChannel
Channel for asynchronous writing of sequences of bytes.
CancellationException
Link copied to clipboard
common
typealias CancellationException = kotlinx.coroutines.CancellationException
ClosedWriteChannelException
Link copied to clipboard
common
class ClosedWriteChannelException(message: String?) : CancellationException
Indicates attempt to write on isClosedForWrite channel that was closed without a cause.
ConsumeEachBufferVisitor
Link copied to clipboard
typealias ConsumeEachBufferVisitor = (buffer: ByteBuffer, last: Boolean) -> Boolean

Visitor function that is invoked for every available buffer (or chunk) of a channel. The last parameter shows that the buffer is known to be the last.

LookAheadSession
Link copied to clipboard
interface LookAheadSession
LookAheadSuspendSession
Link copied to clipboard
interface LookAheadSuspendSession : LookAheadSession
ReaderJob
Link copied to clipboard
common
interface ReaderJob : Job
A coroutine job that is reading from a byte channel
ReaderScope
Link copied to clipboard
common
interface ReaderScope : CoroutineScope
ReadSession
Link copied to clipboard
common
interface ReadSession
SuspendableReadSession
Link copied to clipboard
common
interface SuspendableReadSession : ReadSession
WriterJob
Link copied to clipboard
common
interface WriterJob : Job
A coroutine job that is writing to a byte channel
WriterScope
Link copied to clipboard
common
interface WriterScope : CoroutineScope
WriterSession
Link copied to clipboard
common
interface WriterSession
WriterSuspendSession
Link copied to clipboard
common
interface WriterSuspendSession : WriterSession

Functions

ByteChannel
Link copied to clipboard
common
fun ByteChannel(autoFlush: Boolean = false): ByteChannel
Creates buffered channel for asynchronous reading and writing of sequences of bytes.
fun ByteChannel(autoFlush: Boolean = false): ByteChannel
Creates buffered channel for asynchronous reading and writing of sequences of bytes.
posix
fun ByteChannel(autoFlush: Boolean = false): ByteChannel
Creates buffered channel for asynchronous reading and writing of sequences of bytes.
fun ByteChannel(autoFlush: Boolean = false, exceptionMapper: (Throwable?) -> Throwable?): ByteChannel
Creates buffered channel for asynchronous reading and writing of sequences of bytes using close function to close channel.
ByteReadChannel
Link copied to clipboard
fun ByteReadChannel(content: ByteBuffer): ByteReadChannel
Creates channel for reading from the specified byte buffer.
common
fun ByteReadChannel(content: ByteArray): ByteReadChannel
Creates channel for reading from the specified byte array.
common
fun ByteReadChannel(content: ByteArray, offset: Int): ByteReadChannel
Creates channel for reading from the specified byte array.
common
fun ByteReadChannel(text: String, charset: Charset = Charsets.UTF_8): ByteReadChannel
common
fun ByteReadChannel(content: ByteArray, offset: Int, length: Int): ByteReadChannel
Creates channel for reading from the specified byte array.
fun ByteReadChannel(content: ByteArray, offset: Int, length: Int): ByteReadChannel
Creates channel for reading from the specified byte array.
posix
fun ByteReadChannel(content: ByteArray, offset: Int, length: Int): ByteReadChannel
Creates channel for reading from the specified byte array.
cancel
Link copied to clipboard
common
fun ByteReadChannel.cancel(): Boolean
close
Link copied to clipboard
common
fun ByteWriteChannel.close(): Boolean
Closes this channel with no failure (successfully)
consumeEachBufferRange
Link copied to clipboard
inline suspend fun ByteReadChannel.consumeEachBufferRange(visitor: ConsumeEachBufferVisitor)
For every available bytes range invokes visitor function until it return false or end of stream encountered.
consumeEachRemaining
Link copied to clipboard
inline fun LookAheadSession.consumeEachRemaining(visitor: (ByteBuffer) -> Boolean)
inline suspend fun LookAheadSuspendSession.consumeEachRemaining(visitor: suspend (ByteBuffer) -> Boolean)
copyAndClose
Link copied to clipboard
common
suspend fun ByteReadChannel.copyAndClose(dst: ByteWriteChannel, limit: Long = Long.MAX_VALUE): Long
Reads all the bytes from receiver channel and writes them to dst channel and then closes it.
copyTo
Link copied to clipboard
common
suspend fun ByteReadChannel.copyTo(dst: ByteWriteChannel): Long
Reads bytes from receiver channel and writes them to dst channel.
common
suspend fun ByteChannelSequentialBase.copyTo(dst: ByteChannelSequentialBase, limit: Long = Long.MAX_VALUE): Long
common
suspend fun ByteReadChannel.copyTo(dst: ByteWriteChannel, limit: Long): Long
Reads up to limit bytes from receiver channel and writes them to dst channel.
suspend fun ByteReadChannel.copyTo(dst: ByteWriteChannel, limit: Long): Long
Reads up to limit bytes from receiver channel and writes them to dst channel.
posix
suspend fun ByteReadChannel.copyTo(dst: ByteWriteChannel, limit: Long): Long
Reads up to limit bytes from receiver channel and writes them to dst channel.
discard
Link copied to clipboard
common
suspend fun ByteReadChannel.discard(): Long
Discards all bytes in the channel and suspends until end of stream.
discardExact
Link copied to clipboard
common
inline suspend fun ByteReadChannel.discardExact(n: Long)
Discards exactly n bytes or fails if not enough bytes in the channel
joinTo
Link copied to clipboard
suspend fun ByteChannelSequentialBase.joinTo(dst: ByteChannelSequentialBase, closeOnEnd: Boolean)
suspend fun ByteReadChannel.joinTo(dst: ByteWriteChannel, closeOnEnd: Boolean)
suspend fun ByteReadChannel.joinTo(dst: ByteWriteChannel, closeOnEnd: Boolean)
suspend fun ByteReadChannel.joinTo(dst: ByteWriteChannel, closeOnEnd: Boolean)
makeShared
Link copied to clipboard
common
fun Any.makeShared()
preventFreeze
Link copied to clipboard
common
fun Any.preventFreeze()
printStack
Link copied to clipboard
common
fun Throwable.printStack()
Print exception stacktrace.
fun Throwable.printStack()
Print exception stacktrace.
posix
fun Throwable.printStack()
Print exception stacktrace.
read
Link copied to clipboard
common
inline suspend fun ByteReadChannel.read(desiredSize: Int = 1, block: (source: Memory, start: Long, endExclusive: Long) -> Int): Int
Await until at least desiredSize is available for read or EOF and invoke block function.
readAvailable
Link copied to clipboard
common
suspend fun ByteReadChannel.readAvailable(dst: ByteArray): Int
readDouble
Link copied to clipboard
common
inline suspend fun ByteReadChannel.readDouble(byteOrder: ByteOrder): Double
readDoubleLittleEndian
Link copied to clipboard
common
inline suspend fun ByteReadChannel.readDoubleLittleEndian(): Double
reader
Link copied to clipboard
common
fun CoroutineScope.reader(coroutineContext: CoroutineContext = EmptyCoroutineContext, channel: ByteChannel, block: suspend ReaderScope.() -> Unit): ReaderJob
fun CoroutineScope.reader(coroutineContext: CoroutineContext = EmptyCoroutineContext, autoFlush: Boolean = false, block: suspend ReaderScope.() -> Unit): ReaderJob
fun reader(coroutineContext: CoroutineContext, channel: ByteChannel, parent: Job? = null, block: suspend ReaderScope.() -> Unit): ReaderJob
fun reader(coroutineContext: CoroutineContext, autoFlush: Boolean = false, parent: Job? = null, block: suspend ReaderScope.() -> Unit): ReaderJob
readFloat
Link copied to clipboard
common
inline suspend fun ByteReadChannel.readFloat(byteOrder: ByteOrder): Float
readFloatLittleEndian
Link copied to clipboard
common
inline suspend fun ByteReadChannel.readFloatLittleEndian(): Float
readFully
Link copied to clipboard
common
suspend fun ByteReadChannel.readFully(dst: IoBuffer)
suspend fun ByteReadChannel.readFully(dst: ByteArray)
readInt
Link copied to clipboard
common
inline suspend fun ByteReadChannel.readInt(byteOrder: ByteOrder): Int
readIntLittleEndian
Link copied to clipboard
common
inline suspend fun ByteReadChannel.readIntLittleEndian(): Int
readLong
Link copied to clipboard
common
inline suspend fun ByteReadChannel.readLong(byteOrder: ByteOrder): Long
readLongLittleEndian
Link copied to clipboard
common
inline suspend fun ByteReadChannel.readLongLittleEndian(): Long
readPacket
Link copied to clipboard
common
suspend fun ByteReadChannel.readPacket(size: Int): ByteReadPacket
Reads the specified amount of bytes and makes a byte packet from them.
readRemaining
Link copied to clipboard
common
suspend fun ByteReadChannel.readRemaining(): ByteReadPacket
Reads all remaining bytes and makes a byte packet
suspend fun ByteReadChannel.readRemaining(limit: Long): ByteReadPacket
Reads up to limit bytes and makes a byte packet or until end of stream encountered.
readShort
Link copied to clipboard
common
inline suspend fun ByteReadChannel.readShort(byteOrder: ByteOrder): Short
readShortLittleEndian
Link copied to clipboard
common
inline suspend fun ByteReadChannel.readShortLittleEndian(): Short
readUntilDelimiter
Link copied to clipboard
suspend fun ByteReadChannel.readUntilDelimiter(delimiter: ByteBuffer, dst: ByteBuffer): Int
Reads from the channel to the specified dst byte buffer until one of the following:
  • channel's end

  • dst capacity exceeded

  • delimiter bytes encountered

If delimiter bytes encountered then these bytes remain unconsumed
readUTF8Line
Link copied to clipboard
common
suspend fun ByteReadChannel.readUTF8Line(): String?
readUTF8LineTo
Link copied to clipboard
common
suspend fun ByteReadChannel.readUTF8LineTo(out: Appendable): Boolean
skipDelimiter
Link copied to clipboard
suspend fun ByteReadChannel.skipDelimiter(delimiter: ByteBuffer)
tryCopyException
Link copied to clipboard
fun <E : Throwable> tryCopyException(exception: E, cause: Throwable): E?
Try copy exception using cause as cause.
write
Link copied to clipboard
common
inline suspend fun ByteWriteChannel.write(desiredSpace: Int = 1, block: (freeSpace: Memory, startOffset: Long, endExclusive: Long) -> Int): Int
Await for desiredSpace will be available for write and invoke block function providing Memory instance and the corresponding range suitable for wiring in the memory.
writeAvailable
Link copied to clipboard
common
suspend fun ByteWriteChannel.writeAvailable(src: ByteArray): Int
writeBoolean
Link copied to clipboard
common
suspend fun ByteWriteChannel.writeBoolean(b: Boolean)
writeByte
Link copied to clipboard
common
suspend fun ByteWriteChannel.writeByte(b: Int)
writeChar
Link copied to clipboard
common
suspend fun ByteWriteChannel.writeChar(ch: Char)
Writes UTF16 character
writeDouble
Link copied to clipboard
common
suspend fun ByteWriteChannel.writeDouble(value: Double, byteOrder: ByteOrder)
writeDoubleLittleEndian
Link copied to clipboard
common
suspend fun ByteWriteChannel.writeDoubleLittleEndian(value: Double)
writeFloat
Link copied to clipboard
common
suspend fun ByteWriteChannel.writeFloat(value: Float, byteOrder: ByteOrder)
writeFloatLittleEndian
Link copied to clipboard
common
suspend fun ByteWriteChannel.writeFloatLittleEndian(value: Float)
writeFully
Link copied to clipboard
common
suspend fun ByteWriteChannel.writeFully(src: ByteArray)
writeInt
Link copied to clipboard
common
suspend fun ByteWriteChannel.writeInt(i: Long)
suspend fun ByteWriteChannel.writeInt(value: Int, byteOrder: ByteOrder)
suspend fun ByteWriteChannel.writeInt(i: Long, byteOrder: ByteOrder)
writeIntLittleEndian
Link copied to clipboard
common
suspend fun ByteWriteChannel.writeIntLittleEndian(value: Int)
writeLong
Link copied to clipboard
common
suspend fun ByteWriteChannel.writeLong(value: Long, byteOrder: ByteOrder)
writeLongLittleEndian
Link copied to clipboard
common
suspend fun ByteWriteChannel.writeLongLittleEndian(value: Long)
writePacket
Link copied to clipboard
common
inline suspend fun ByteWriteChannel.writePacket(headerSizeHint: Int = 0, builder: BytePacketBuilder.() -> Unit)
writePacketSuspend
Link copied to clipboard
common
suspend fun ByteWriteChannel.writePacketSuspend(builder: suspend BytePacketBuilder.() -> Unit)
writer
Link copied to clipboard
common
fun CoroutineScope.writer(coroutineContext: CoroutineContext = EmptyCoroutineContext, channel: ByteChannel, block: suspend WriterScope.() -> Unit): WriterJob
fun CoroutineScope.writer(coroutineContext: CoroutineContext = EmptyCoroutineContext, autoFlush: Boolean = false, block: suspend WriterScope.() -> Unit): WriterJob
fun writer(coroutineContext: CoroutineContext, channel: ByteChannel, parent: Job? = null, block: suspend WriterScope.() -> Unit): WriterJob
fun writer(coroutineContext: CoroutineContext, autoFlush: Boolean = false, parent: Job? = null, block: suspend WriterScope.() -> Unit): WriterJob
writeShort
Link copied to clipboard
common
suspend fun ByteWriteChannel.writeShort(s: Int)
suspend fun ByteWriteChannel.writeShort(s: Int, byteOrder: ByteOrder)
suspend fun ByteWriteChannel.writeShort(value: Short, byteOrder: ByteOrder)
writeShortLittleEndian
Link copied to clipboard
common
suspend fun ByteWriteChannel.writeShortLittleEndian(value: Short)
writeStringUtf8
Link copied to clipboard
common
suspend fun ByteWriteChannel.writeStringUtf8(s: CharSequence)
suspend fun ByteWriteChannel.writeStringUtf8(s: String)

Properties

EmptyByteReadChannel
Link copied to clipboard
common
val EmptyByteReadChannel: ByteReadChannel
Byte channel that is always empty.