read

open fun read(dst: ByteBuffer): Int

Reads bytes from this channel into the given buffer.

If the channels position is beyond the current end of the underlying data source then end-of-file (-1) is returned.

The bytes are read starting at the channel's current position, and after some number of bytes are read (up to the remaining number of bytes in the buffer) the channel's position is increased by the number of bytes actually read. The bytes will be read into the buffer starting at the buffer's current position. The buffer's limit is not changed.

The call may block if other threads are also attempting to read from the same channel.

Return

the number of bytes actually read, or -1 if the end of the data has been reached

Parameters

buffer

the byte buffer to receive the bytes.

Throws

if another thread closes the channel during the read.

if another thread interrupts the calling thread while the operation is in progress. The interrupt state of the calling thread is set and the channel is closed.

if the channel is closed.

another I/O error occurs, details are in the message.

if the channel was not opened for reading.