ByteWriteChannel

interface ByteWriteChannel : ObjectWrapper<ERROR CLASS: Symbol not found for io.ktor.utils.io.ByteWriteChannel>

脚本层对 Ktor io.ktor.utils.io.ByteWriteChannel 的包装。

提供异步、顺序写入字节的通道,不支持并发写(除非文档特别说明)。 所有挂起函数均可在脚本协程作用域内安全调用。

常用步骤

  1. flushflushAndClose 保证数据到达对端。

  2. 异常/取消时调用 cancel 立即关闭通道。

Author

M8Test, [email protected], https://m8test.com

See also

io.ktor.utils.io.ByteWriteChannel

Functions

Link copied to clipboard
abstract fun also(block: (ERROR CLASS: Symbol not found for io.ktor.utils.io.ByteWriteChannel) -> Unit): ObjectWrapper<ERROR CLASS: Symbol not found for io.ktor.utils.io.ByteWriteChannel>

对 ObjectWrapper 调用给定的 block 函数,并返回 ObjectWrapper 本身。

Link copied to clipboard
abstract fun apply(block: ERROR CLASS: Symbol not found for io.ktor.utils.io.ByteWriteChannel.() -> Unit): ObjectWrapper<ERROR CLASS: Symbol not found for io.ktor.utils.io.ByteWriteChannel>

对 ObjectWrapper 调用给定的 block 函数,并返回 ObjectWrapper 本身。

Link copied to clipboard
abstract fun cancel(cause: Throwable?)

立即取消写入通道,并可选地给出原因。

Link copied to clipboard
abstract fun flush(scope: CoroutineScope): Deferred<Unit>

挂起直到缓冲区数据全部刷送到对端,不关闭通道。

Link copied to clipboard
abstract fun flushAndClose(scope: CoroutineScope): Deferred<Unit>

挂起刷新缓冲区并关闭写入端。

Link copied to clipboard
abstract fun getOrigin(): ERROR CLASS: Symbol not found for io.ktor.utils.io.ByteWriteChannel

获取原始的对象.

Link copied to clipboard
abstract fun isClosedForWrite(): Boolean

当前通道是否已关闭写入端

Link copied to clipboard
abstract fun <R> let(block: (ERROR CLASS: Symbol not found for io.ktor.utils.io.ByteWriteChannel) -> R): ObjectWrapper<R>?

对 ObjectWrapper 调用给定的 block 函数,并返回 block 函数的结果包装在 ObjectWrapper 中。

Link copied to clipboard
abstract fun <R> run(block: ERROR CLASS: Symbol not found for io.ktor.utils.io.ByteWriteChannel.() -> R): ObjectWrapper<R>?

对 ObjectWrapper 调用给定的 block 函数,并返回 block 函数的结果包装在 ObjectWrapper 中。

Link copied to clipboard
abstract fun setOrigin(origin: ERROR CLASS: Symbol not found for io.ktor.utils.io.ByteWriteChannel)

设置原始对象

Link copied to clipboard
abstract fun takeIf(predicate: (ERROR CLASS: Symbol not found for io.ktor.utils.io.ByteWriteChannel) -> Boolean): ObjectWrapper<ERROR CLASS: Symbol not found for io.ktor.utils.io.ByteWriteChannel>?

如果 ObjectWrapper 满足给定的 predicate,则返回 ObjectWrapper 本身,否则返回 null 包装在 ObjectWrapper? 中。

Link copied to clipboard
abstract fun takeUnless(predicate: (ERROR CLASS: Symbol not found for io.ktor.utils.io.ByteWriteChannel) -> Boolean): ObjectWrapper<ERROR CLASS: Symbol not found for io.ktor.utils.io.ByteWriteChannel>?

如果 ObjectWrapper 不满足给定的 predicate,则返回 ObjectWrapper 本身,否则返回 null 包装在 ObjectWrapper? 中。

Link copied to clipboard
abstract fun writeByte(scope: CoroutineScope, value: Byte): Deferred<Unit>

异步地向通道写入一个单独的字节。

Link copied to clipboard
abstract fun writeFully(scope: CoroutineScope, data: ByteArray, start: Int, end: Int): Deferred<Unit>

异步地将字节数组 data 的指定范围(从 startend)完全写入通道。

Link copied to clipboard
abstract fun writeInt(scope: CoroutineScope, value: Int): Deferred<Unit>

异步地向通道写入一个 4 字节的整数(大端序)。

Link copied to clipboard
abstract fun writeLong(scope: CoroutineScope, value: Long): Deferred<Unit>

异步地向通道写入一个 8 字节的长整数(大端序)。

Link copied to clipboard
abstract fun writeStringUtf8(scope: CoroutineScope, value: String): Deferred<Unit>

异步地将一个字符串以 UTF-8 编码写入通道。