Package io.ktor.util.cio

Types

Link copied to clipboard
class ByteBufferPool : DefaultPool<ByteBuffer>
Link copied to clipboard
open class ChannelIOException(message: String, exception: Throwable) : IOException

An exception thrown when an IO error occurred during reading or writing to/from the underlying channel. The typical error is "connection reset" and so on.

Link copied to clipboard
class ChannelReadException(message: String, exception: Throwable) : ChannelIOException

An exception that is thrown when an IO error occurred during reading from the request channel. Usually it happens when a remote client closed the connection.

Link copied to clipboard
class ChannelWriteException(message: String, exception: Throwable) : ChannelIOException

An exception that is thrown when an IO error occurred during writing to the destination channel. Usually it happens when a remote client closed the connection.

Link copied to clipboard
class Semaphore(limit: Int)

Functions

Link copied to clipboard
fun ByteWriteChannel.bufferedWriter(charset: Charset = Charsets.UTF_8): BufferedWriter

Open a buffered writer to the channel

Link copied to clipboard
inline suspend fun ByteReadChannel.pass(buffer: ByteBuffer, block: (ByteBuffer) -> Unit)

Read data chunks from ByteReadChannel using buffer

Link copied to clipboard
fun Path.readChannel(): ByteReadChannel
fun Path.readChannel(start: Long, endInclusive: Long): ByteReadChannel

Open a read channel for file and launch a coroutine to fill it. Please note that file reading is blocking so if you are starting it on Dispatchers.Unconfined it may block your async code

fun File.readChannel(start: Long = 0, endInclusive: Long = -1, coroutineContext: CoroutineContext = Dispatchers.IO): ByteReadChannel

Open a read channel for file and launch a coroutine to fill it. Please note that file reading is blocking so if you are starting it on Dispatchers.Unconfined it may block your async code and freeze the whole application when runs on a pool that is not intended for blocking operations. This is why coroutineContext should have Dispatchers.IO or a coroutine dispatcher that is properly configured for blocking IO.

Link copied to clipboard
suspend fun ByteReadChannel.toByteArray(limit: Int = Int.MAX_VALUE): ByteArray
Link copied to clipboard
fun InputStream.toByteReadChannel(pool: ObjectPool<ByteBuffer> = KtorDefaultPool, context: CoroutineContext = Dispatchers.Unconfined, parent: Job = Job()): ByteReadChannel

Open a channel and launch a coroutine to copy bytes from the input stream to the channel. Please note that it may block your async code when started on Dispatchers.Unconfined since InputStream is blocking on it's nature

Link copied to clipboard
inline fun ByteWriteChannel.use(block: ByteWriteChannel.() -> Unit)

Executes block on ByteWriteChannel and close it down correctly whether an exception

Link copied to clipboard
suspend fun ByteWriteChannel.write(string: String, charset: Charset = Charsets.UTF_8)

Write a string in the specified charset

Link copied to clipboard
fun File.writeChannel(coroutineContext: CoroutineContext = Dispatchers.IO): ByteWriteChannel

Open a write channel for the file and launch a coroutine to read from it. Please note that file writing is blocking so if you are starting it on Dispatchers.Unconfined it may block your async code and freeze the whole application when runs on a pool that is not intended for blocking operations. This is why coroutineContext should have Dispatchers.IO or a coroutine dispatcher that is properly configured for blocking IO.

Link copied to clipboard
fun ByteWriteChannel.writer(charset: Charset = Charsets.UTF_8): Writer

Open a writer to the channel

Properties

Link copied to clipboard
val KtorDefaultPool: ObjectPool<ByteBuffer>

The default ktor byte buffer pool