Package-level declarations

Types

Link copied to clipboard

Sequential (non-concurrent) byte channel implementation

Link copied to clipboard
interface ByteReadChannel

Channel for asynchronous reading of sequences of bytes. This is a single-reader channel.

Link copied to clipboard

Channel for asynchronous writing of sequences of bytes. This is a single-writer channel.

Link copied to clipboard
typealias CancellationException = kotlinx.coroutines.CancellationException
Link copied to clipboard
interface ChannelJob
Link copied to clipboard
typealias ClosedWriteChannelException = IOException
Link copied to clipboard
class ConcurrentIOException(taskName: String, cause: Throwable? = null) : IllegalStateException

Thrown when a coroutine awaiting I/O is replaced by another.

Link copied to clipboard
Link copied to clipboard

API marked with this annotation is internal, and it is not intended to be used outside Ktor. It could be modified or removed without any notice. Using it outside Ktor could cause undefined behaviour and/or any unexpected effects.

Link copied to clipboard
Link copied to clipboard

API marked with this annotation is experimental and is not guaranteed to be stable.

Link copied to clipboard
Link copied to clipboard
class LookAheadSuspendSession(channel: <Error class: unknown class>)
Link copied to clipboard

API marked with this annotation is intended to become public in the future version. Usually it means that the API can't be public at the moment of development due to compatibility guarantees restrictions.

Link copied to clipboard
Link copied to clipboard
class ReaderScope(val channel: ByteReadChannel, val coroutineContext: CoroutineContext) : CoroutineScope
Link copied to clipboard
Link copied to clipboard
class WriterScope(val channel: ByteWriteChannel, val coroutineContext: CoroutineContext) : CoroutineScope

Properties

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

Functions

Link copied to clipboard
fun ByteChannel.attachJob(job: Job)

Ensures that when the given job is canceled, the ByteChannel is canceled with the same exception.

Link copied to clipboard
Link copied to clipboard
fun ByteReadChannel(source: Source): ByteReadChannel
fun ByteReadChannel(text: String, charset: Charset = Charsets.UTF_8): ByteReadChannel

fun ByteReadChannel(content: ByteArray, offset: Int = 0, length: Int = content.size): ByteReadChannel

Creates a channel for reading from the specified byte array. Please note that it could use content directly or copy its bytes depending on the platform

fun ByteReadChannel(content: ByteBuffer): <Error class: unknown class>

Creates a channel for reading from the specified byte buffer.

Link copied to clipboard
fun ByteString(buffer: ByteBuffer): ByteString
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
suspend fun ByteReadChannel.copyTo(channel: ByteWriteChannel, limit: Long): Long
suspend fun <Error class: unknown class>.copyTo(channel: WritableByteChannel, limit: Long = Long.MAX_VALUE): Long

Copy up to limit bytes to blocking NIO channel. Copying to a non-blocking channel requires selection and not supported. It is suspended if no data are available in a byte channel but may block if destination NIO channel blocks.

Link copied to clipboard
suspend fun ByteReadChannel.discard(max: Long = Long.MAX_VALUE): Long
Link copied to clipboard
suspend fun ByteReadChannel.discardExact(value: Long)
Link copied to clipboard

Suspends the channel until it is exhausted or gets closed. If the read buffer is empty, it suspends until there are bytes available in the channel. Once the channel is exhausted or closed, this function returns.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
suspend fun ChannelJob.join()
Link copied to clipboard
suspend fun <Error class: unknown class>.lookAhead(block: suspend LookAheadSuspendSession.() -> Unit)
Link copied to clipboard
suspend fun <Error class: unknown class>.lookAheadSuspend(block: suspend LookAheadSuspendSession.() -> Unit)
Link copied to clipboard
suspend fun ByteReadChannel.peek(count: Int): ByteString?

Retrieves, but does not consume, up to the specified number of bytes from the current position in this ByteReadChannel.

Link copied to clipboard
inline suspend fun ByteReadChannel.read(crossinline block: suspend (ByteArray, Int, Int) -> Int): Int
inline suspend fun <Error class: unknown class>.read(min: Int = 1, noinline consumer: (ByteBuffer) -> Unit)

Invokes consumer when it will be possible to read at least min bytes providing byte buffer to it so lambda can read from the buffer up to ByteBuffer.remaining bytes. If there are no min bytes available then the invocation could suspend until the requirement will be met.

Link copied to clipboard
fun ByteReadChannel.readAvailable(min: Int, block: (Buffer) -> Int): Int

Invokes block if it is possible to read at least min byte providing buffer to it so lambda can read from the buffer up to Buffer.readRemaining bytes. If there are no min bytes available then the invocation returns -1.

suspend fun ByteReadChannel.readAvailable(buffer: ByteArray, offset: Int = 0, length: Int = buffer.size - offset): Int

Reads all available bytes to dst buffer and returns immediately or suspends if no bytes available

suspend fun <Error class: unknown class>.readAvailable(buffer: ByteBuffer): Int

Reads bytes from the channel and writes them to the buffer up to its limit. If the channel's read buffer is exhausted, it suspends until there are bytes available.

fun <Error class: unknown class>.readAvailable(block: (ByteBuffer) -> Int): Int

Invokes block if it is possible to read at least min byte providing byte buffer to it so lambda can read from the buffer up to ByteBuffer.available bytes. If there are no min bytes available then the invocation returns 0.

suspend fun ByteReadChannel.readAvailable(dst: CPointer<ByteVar>, offset: Int, length: Int): Int

Reads all available bytes to dst buffer and returns immediately or suspends if no bytes available

fun Input.readAvailable(cPointer: CPointer<ByteVar>, offset: Int, length: Int): Int
Link copied to clipboard
suspend fun ByteReadChannel.readBuffer(): Buffer
suspend fun ByteReadChannel.readBuffer(max: Int): Buffer
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun CoroutineScope.reader(coroutineContext: CoroutineContext, channel: ByteChannel, block: suspend ReaderScope.() -> Unit): ReaderJob
fun CoroutineScope.reader(coroutineContext: CoroutineContext = EmptyCoroutineContext, autoFlush: Boolean = false, block: suspend ReaderScope.() -> Unit): ReaderJob
Link copied to clipboard
suspend fun ByteReadChannel.readFully(out: ByteArray, start: Int = 0, end: Int = out.size)

Reads bytes from start to end into the provided out buffer, or fails if the channel has been closed.

suspend fun <Error class: unknown class>.readFully(buffer: ByteBuffer)
Link copied to clipboard
suspend fun ByteReadChannel.readInt(): Int
Link copied to clipboard
Link copied to clipboard
suspend fun ByteReadChannel.readPacket(packet: Int): Source

Reads a packet of packet bytes from the channel.

Link copied to clipboard
suspend fun ByteReadChannel.readRemaining(): Source
suspend fun ByteReadChannel.readRemaining(max: Long): Source
Link copied to clipboard
Link copied to clipboard
fun Source.readText(): String
Link copied to clipboard
suspend fun ByteReadChannel.readUntil(matchString: ByteString, writeChannel: ByteWriteChannel, limit: Long = Long.MAX_VALUE, ignoreMissing: Boolean = false): Long

Reads bytes from the ByteReadChannel until a specified sequence of bytes is encountered or the specified limit is reached.

Link copied to clipboard
suspend fun ByteReadChannel.readUTF8Line(max: Int = Int.MAX_VALUE): String?

Reads a line of UTF-8 characters from the ByteReadChannel. It recognizes CR, LF and CRLF as line delimiters.

Link copied to clipboard
suspend fun ByteReadChannel.readUTF8LineTo(out: Appendable, max: Int = Int.MAX_VALUE): Boolean

Reads a line of UTF-8 characters to the specified out buffer. It recognizes CR, LF and CRLF as a line delimiter.

Link copied to clipboard
fun Sink.release()
Link copied to clipboard
suspend fun <Error class: unknown class>.skipDelimiter(delimiter: ByteBuffer)
suspend fun <Error class: unknown class>.skipDelimiter(delimiter: ByteString)
Link copied to clipboard
suspend fun ByteReadChannel.skipIfFound(byteString: ByteString): Boolean

Skips the specified byteString in the ByteReadChannel if it is found at the current position.

Link copied to clipboard
Link copied to clipboard
suspend fun ByteWriteChannel.write(desiredSpace: Int = 1, block: (ByteArray, Int, Int) -> 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. The block function should return number of bytes were written, possibly 0.

suspend fun <Error class: unknown class>.write(min: Int = 1, block: (buffer: ByteBuffer) -> Unit)
Link copied to clipboard
fun <Error class: unknown class>.writeAvailable(buffer: ByteBuffer)

fun <Error class: unknown class>.writeAvailable(min: Int = 1, block: (ByteBuffer) -> Unit): Int

Invokes block if it is possible to write at least min byte providing byte buffer to it so lambda can write to the buffer up to ByteBuffer.remaining bytes. If there are no min bytes spaces available then the invocation returns 0.

Link copied to clipboard
suspend fun ByteWriteChannel.writeBuffer(value: RawSource)
Link copied to clipboard
suspend fun ByteWriteChannel.writeByte(value: Byte)
Link copied to clipboard
Link copied to clipboard
suspend fun <Error class: unknown class>.writeByteBuffer(value: ByteBuffer)
Link copied to clipboard
suspend fun ByteWriteChannel.writeFully(value: ByteArray, startIndex: Int = 0, endIndex: Int = value.size)
suspend fun <Error class: unknown class>.writeFully(value: ByteBuffer)
suspend fun ByteWriteChannel.writeFully(value: CPointer<ByteVar>, offset: Int, length: Int)
suspend fun ByteWriteChannel.writeFully(src: CPointer<ByteVar>, offset: Long, length: Long)
Link copied to clipboard
suspend fun ByteWriteChannel.writeInt(value: Int)
Link copied to clipboard
suspend fun ByteWriteChannel.writeLong(value: Long)
Link copied to clipboard
suspend fun ByteWriteChannel.writePacket(copy: Buffer)
suspend fun ByteWriteChannel.writePacket(copy: Source)
Link copied to clipboard
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
Link copied to clipboard
suspend fun ByteWriteChannel.writeShort(value: Short)
Link copied to clipboard
suspend fun ByteWriteChannel.writeSource(source: Source)
Link copied to clipboard
suspend fun ByteWriteChannel.writeString(value: String)
Link copied to clipboard