write

open override fun <A> write(buffer: CharBuffer, attachment: A?, handler: CompletionHandler<Int, A>)

Writes a sequence of characters to this TextOutputChannel from the given buffer.

This method initiates an asynchronous write operation to write a sequence of characters to this channel from the given buffer. The supplied CompletionHandler is invoked when the write operation completes (or fails). The result passed to the completion handler is the number of characters written.

The write operation may write up to r characters to the channel, where r is the number in the buffer at the time that the write is attempted. If r is 0, then the write operation completes immediately with a result of 0 without initiating an I/O operation.

Suppose that a character sequence of length n is written, where 0 < n ≤ r. This character sequence will be transferred from the buffer starting at index p, where p is the buffer's position at the moment the write is performed; the index of the last character written will be p + n - 1. Upon completion the buffer's position will be equal to p + n; its limit will not have changed.

Buffers are not safe for use by multiple concurrent threads, so care should be taken to avoid accessing the buffer until the operation has completed.

This method may be invoked at any time.

Parameters

A

The type of attachment accepted by the CompletionHandler.

buffer

The buffer containing the characters to be transmitted.

attachment

An arbitrary value that should be made available to the CompletionHandler, irrespective of success.

handler

What to do when the I/O operation succeeds or fails.


open override fun <A> write(data: String, attachment: A?, handler: CompletionHandler<Int, A>)

Writes a sequence of characters to this TextOutputChannel from the given string.

This method initiates an series of asynchronous write operations to write a sequence of characters to this channel from the given string. The supplied CompletionHandler is invoked when the entire string has been written (or when any intermediate write fails). The result passed to the completion handler is the number of written.

Parameters

A

The type of attachment accepted by the CompletionHandler.

data

The string to be written.

attachment

An arbitrary value that should be made available to the CompletionHandler, irrespective of success.

handler

What to do when the I/O operation succeeds or fails.