Package kotlinx.coroutines.experimental.io

Byte I/O channels (unstable, work in progress).

Types

ByteChannel

interface ByteChannel : ByteReadChannel, ByteWriteChannel

Channel for asynchronous reading and writing of sequences of bytes. This is a buffered single-reader single-writer channel.

ByteReadChannel

interface ByteReadChannel

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

ByteWriteChannel

interface ByteWriteChannel

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

LookAheadSession

interface LookAheadSession

LookAheadSuspendSession

interface LookAheadSuspendSession : LookAheadSession

ReaderJob

interface ReaderJob : Job

A coroutine job that is reading from a byte channel

ReaderScope

interface ReaderScope : CoroutineScope

WriterJob

interface WriterJob : Job

A coroutine job that is writing to a byte channel

WriterScope

interface WriterScope : CoroutineScope

WriterSession

interface WriterSession

WriterSuspendSession

interface WriterSuspendSession : WriterSession

Exceptions

ClosedWriteChannelException

class ClosedWriteChannelException : CancellationException

Indicates attempt to write on isClosedForWrite channel that was closed without a cause. A failed channel rethrows the original close cause exception on send attempts.

Type Aliases

ByteBuffer

typealias ByteBuffer = ByteBuffer

Byte buffer.

ByteOrder

typealias ByteOrder = ByteOrder

Byte order.

ConsumeEachBufferVisitor

typealias ConsumeEachBufferVisitor = (buffer: ByteBuffer, last: Boolean) -> Boolean

Properties

EmptyByteReadChannel

val EmptyByteReadChannel: ByteReadChannel

Byte channel that is always empty.

Functions

ByteChannel

fun ByteChannel(autoFlush: Boolean = false): ByteChannel

Creates buffered channel for asynchronous reading and writing of sequences of bytes.

ByteReadChannel

fun ByteReadChannel(content: ByteBuffer): ByteReadChannel

Creates channel for reading from the specified byte buffer.

fun ByteReadChannel(content: ByteArray): ByteReadChannel

Creates channel for reading from the specified byte array.

consumeEachRemaining

fun LookAheadSession.consumeEachRemaining(
    visitor: (ByteBuffer) -> Boolean
): Unit

copyAndClose

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. Closes dst channel if fails to read or write with cause exception.

copyTo

suspend fun ByteReadChannel.copyTo(
    dst: ByteWriteChannel,
    limit: Long = Long.MAX_VALUE
): Long

Reads up to limit bytes from receiver channel and writes them to dst channel. Closes dst channel if fails to read or write with cause exception.

joinTo

suspend fun ByteReadChannel.joinTo(
    dst: ByteWriteChannel,
    closeOnEnd: Boolean
): Unit

readASCIILine

suspend fun ByteReadChannel.readASCIILine(
    estimate: Int = 16,
    limit: Int = Int.MAX_VALUE
): String?

readLine

suspend fun ByteReadChannel.readLine(
    estimate: Int = 16,
    limit: Int = Int.MAX_VALUE
): String?

readRemaining

suspend fun ByteReadChannel.readRemaining(
    limit: Int = Int.MAX_VALUE
): ByteReadPacket

Reads all the bytes from receiver channel and builds a packet that is returned unless the specified limit exceeded. It will simply stop reading and return packet of size limit in this case

readUTF8Line

suspend fun ByteReadChannel.readUTF8Line(
    estimate: Int = 16,
    limit: Int = Int.MAX_VALUE
): String?

readUntilDelimiter

suspend fun ByteReadChannel.readUntilDelimiter(
    delimiter: ByteBuffer,
    dst: ByteBuffer
): Int

Reads from the channel to the specified dst byte buffer until one of the following:

reader

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

skipDelimiter

suspend fun ByteReadChannel.skipDelimiter(
    delimiter: ByteBuffer
): Unit

write

suspend fun ByteWriteChannel.write(src: ByteArray): Unit
suspend fun ByteWriteChannel.write(
    src: ByteArray,
    offset: Int,
    length: Int
): Unit

See java.io.DataOutput.write

writeBoolean

suspend fun ByteWriteChannel.writeBoolean(b: Boolean): Unit

writeByte

suspend fun ByteWriteChannel.writeByte(b: Int): Unit

writeBytes

suspend fun ByteWriteChannel.writeBytes(s: String): Unit

See java.io.DataOutput.writeBytes

writeChar

suspend fun ByteWriteChannel.writeChar(ch: Char): Unit

Writes UTF16 character

writeChars

suspend fun ByteWriteChannel.writeChars(s: String): Unit

See java.io.DataOutput.writeChars

writeInt

suspend fun ByteWriteChannel.writeInt(i: Long): Unit

writePacket

suspend fun ByteWriteChannel.writePacket(
    headerSizeHint: Int = 0,
    builder: ByteWritePacket.() -> Unit
): Unit

writePacketSuspend

suspend fun ByteWriteChannel.writePacketSuspend(
    builder: suspend ByteWritePacket.() -> Unit
): Unit

writeShort

suspend fun ByteWriteChannel.writeShort(s: Int): Unit

writeStringUtf8

suspend fun ByteWriteChannel.writeStringUtf8(
    s: CharSequence
): Unit
suspend fun ByteWriteChannel.writeStringUtf8(
    s: CharBuffer
): Unit
suspend fun ByteWriteChannel.writeStringUtf8(s: String): Unit

writeUTF

suspend fun ByteWriteChannel.writeUTF(s: String): Unit

See java.io.DataOutput.writeUTF

writer

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