read

abstract fun <A> read(    buffer: CharBuffer,     attachment: A?,     handler: CompletionHandler<Int, A>)

Reads a sequence of characters from this reader into the given buffer.

This method initiates an asynchronous read operation to read a sequence of channels from this channel into the given buffer. The supplied CompletionHandler is invoked when the read operation completes (or fails). The result passed to the completion handler is the number of characters read or -1 if no characters could be read because the channel has reached end-of-stream.

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

Suppose that a character sequence of length n is read, where 0 < n ≤ r. This character sequence will be transferred into the buffer so that the first byte in the sequence is at index p and the last byte is at index p + n - 1, where p is the buffer's position at the moment that the read is performed. 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 asynchronous read operation has completed.

This method may be invoked at any time.

Parameters

A

The type of attachment accepted by the CompletionHandler.

buffer

The buffer into which characters should be read.

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.