tuweni / org.apache.tuweni.net.coroutines / ReadableCoroutineByteChannel / tryRead

tryRead

abstract fun tryRead(dst: ByteBuffer): Int (source)

Reads a sequence of bytes from this channel into the given buffer, if any bytes are immediately available.

An attempt is made to read up to r bytes from the channel, where r is the number of bytes remaining in the buffer, that is, dst.remaining(), at the moment this method is invoked.

Parameters

dst - The buffer into which bytes are to be transferred.

Exceptions

NonReadableChannelException - If this channel was not opened for reading.

ClosedChannelException - If the channel is closed.

AsynchronousCloseException - If another thread closes this channel while the read operation is in progress.

ClosedByInterruptException - If another thread interrupts the current thread while the read operation is in progress, thereby closing the channel and setting the current thread's interrupt status.

IOException - If some other I/O error occurs.

Return
The number of bytes read, possibly zero, or -1 if the channel has reached end-of-stream.