Package java.nio.channels
Interface ScatteringByteChannel
- All Superinterfaces:
AutoCloseable,Channel,Closeable,ReadableByteChannel
- All Known Implementing Classes:
DatagramChannel,FileChannel,Pipe.SourceChannel,SocketChannel
public interface ScatteringByteChannel extends ReadableByteChannel
The interface for channels that can read data into a set of buffers in a
single operation. The corresponding interface for writes is
GatheringByteChannel.-
Method Summary
Modifier and Type Method Description longread(ByteBuffer[] buffers)Reads bytes from this channel into the specified array of buffers.longread(ByteBuffer[] buffers, int offset, int length)Attempts to read allremaining()bytes fromlengthbyte buffers, in order, starting atbuffers[offset].Methods inherited from interface java.nio.channels.ReadableByteChannel
read
-
Method Details
-
read
Reads bytes from this channel into the specified array of buffers.This method is equivalent to
read(buffers, 0, buffers.length);- Parameters:
buffers- the array of byte buffers to store the bytes being read.- Returns:
- the number of bytes actually read.
- Throws:
AsynchronousCloseException- if the channel is closed by another thread during this read operation.ClosedByInterruptException- 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.ClosedChannelException- if the channel is closed.IOException- if another I/O error occurs; details are in the message.NonWritableChannelException- if the channel has not been opened in a mode that permits reading.
-
read
Attempts to read allremaining()bytes fromlengthbyte buffers, in order, starting atbuffers[offset]. The number of bytes actually read is returned.If a read operation is in progress, subsequent threads will block until the read is completed and will then contend for the ability to read.
- Parameters:
buffers- the array of byte buffers into which the bytes will be copied.offset- the index of the first buffer to store bytes in.length- the maximum number of buffers to store bytes in.- Returns:
- the number of bytes actually read.
- Throws:
AsynchronousCloseException- if the channel is closed by another thread during this read operation.ClosedByInterruptException- 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.ClosedChannelException- if the channel is closed.IndexOutOfBoundsException- ifoffset < 0orlength < 0, or ifoffset + lengthis greater than the size ofbuffers.IOException- if another I/O error occurs; details are in the message.NonWritableChannelException- if the channel has not been opened in a mode that permits reading.
-