public interface ScatteringByteChannel extends ReadableByteChannel
一个散射读操作读取,在一次调用中,一个字节序列转换成一个或多个给定序列的缓冲区。当实现网络协议或文件格式时,散射读取通常是有用的,例如,将数据分组到由一个或多个固定长度的头和一个可变长度的身体组成的段中。类似的收集写操作是在GatheringByteChannel
接口定义。
Modifier and Type | Method and Description |
---|---|
long |
read(ByteBuffer[] dsts)
从这个通道读入给定的缓冲区中的一个字节序列。
|
long |
read(ByteBuffer[] dsts, int offset, int length)
读这信入子序列给定的缓冲区字节序列。
|
read
long read(ByteBuffer[] dsts, int offset, int length) throws IOException
在读到R字节从这个渠道尝试调用该方法,其中R是总字节数剩下的指定序列给定的缓冲数组,即,
此刻,调用该方法。dsts[offset].remaining() + dsts[offset+1].remaining() + ... + dsts[offset+length-1].remaining()
假设一个长度字节序列N是阅读,在0 <= N <= R.到这个序列的第一dsts[offset].remaining()字节转换成缓冲dsts[offset],到下一个dsts[offset+1].remaining()字节转换成缓冲dsts[offset+1],等等,直到整个字节序列转换为给定的缓冲区。尽可能多的字节被传送到每个缓冲区,因此每个更新的缓冲区的最终位置,除了最后一个更新的缓冲区,保证是等于该缓冲区的限制。
这种方法可能在任何时候被调用。如果另一个线程已经在这个通道上启动了一个读操作,那么这个方法的调用将阻塞,直到第一个操作完成。
dsts
的缓冲区字节被转移
offset
-在第一缓冲区中的字节将缓冲数组的偏移;必须是非负的且不大于
dsts.length
length
-缓冲区的最大数量被访问;必须是非负的且不大于
dsts.length -
offset
IndexOutOfBoundsException
-如果在
offset和
length参数的前提条件不成立
NonReadableChannelException
-如果这通道不打开阅读
ClosedChannelException
-如果这通道关闭
AsynchronousCloseException
如果另一个线程关闭通道而读操作正在进行中
ClosedByInterruptException
如果另一个线程中断当前线程在读操作中,从而关闭通道和设置当前线程的中断状态
IOException
-如果其他I/O错误发生
long read(ByteBuffer[] dsts) throws IOException
这种形式的c.read(dsts)方法调用的行为以同样的方式调用
c.read(dsts, 0, dsts.length);
dsts
的缓冲区字节被转移
NonReadableChannelException
-如果这通道不打开阅读
ClosedChannelException
-如果这通道关闭
AsynchronousCloseException
如果另一个线程关闭通道而读操作正在进行中
ClosedByInterruptException
如果另一个线程中断当前线程在读操作中,从而关闭通道和设置当前线程的中断状态
IOException
-如果其他I/O错误发生
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.