public interface SeekableByteChannel extends ByteChannel
Modifier and Type | Method and Description |
---|---|
long |
position()
返回此通道的位置。
|
SeekableByteChannel |
position(long newPosition)
设置此通道的位置。
|
int |
read(ByteBuffer dst)
从这个通道读取一个字节序列到给定的缓冲区中。
|
long |
size()
返回此通道连接的实体的当前大小。
|
SeekableByteChannel |
truncate(long size)
截断的实体,此通道是连接到给定的尺寸。
|
int |
write(ByteBuffer src)
从给定的缓冲区中写入该通道的一个字节序列。
|
int read(ByteBuffer dst) throws IOException
在该通道的当前位置开始读取字节,然后用实际读取的字节数进行更新。否则,此方法的行为完全按照ReadableByteChannel
指定界面。
read
接口
ReadableByteChannel
dst
-缓冲区中的字节都被转移
ClosedChannelException
-如果这通道关闭
AsynchronousCloseException
如果另一个线程关闭通道而读操作正在进行中
ClosedByInterruptException
如果另一个线程中断当前线程在读操作中,从而关闭通道和设置当前线程的中断状态
IOException
-如果其他I/O错误发生
int write(ByteBuffer src) throws IOException
字节写入开始在这个频道的当前位置,除非通道连接到如打开的文件,与APPEND
选择实体,在这种情况下,位置是第一个提出结束。该通道连接的实体生长,如果必要的话,以容纳写入的字节,然后将该位置与实际写入的字节数进行更新。否则,此方法的行为完全由WritableByteChannel
指定界面。
write
接口
WritableByteChannel
src
-缓冲器字节进行检索
ClosedChannelException
-如果这通道关闭
AsynchronousCloseException
如果另一个线程关闭通道,而写操作正在进行中
ClosedByInterruptException
如果另一个线程中断当前线程,而写操作正在进行,从而关闭通道和设置当前线程的中断状态
IOException
-如果其他I/O错误发生
long position() throws IOException
ClosedChannelException
-如果这通道关闭
IOException
-如果其他I/O错误发生
SeekableByteChannel position(long newPosition) throws IOException
将该位置设置为大于当前大小的值是合法的,但不改变实体的大小。稍后在这样一个位置读取字节的尝试将立即返回一个文件指示的结束。稍后尝试在这样一个位置上写字节将导致实体增长,以适应新的字节;任何字节的值之间的前一个文件和新写的字节是未指定的。
设置通道的位置是不推荐,当连接到一个实体,通常是一个文件,这是打开的APPEND
选项。当打开附加时,位置是第一个先进的结束前写。
newPosition
-新的位置,一个非负整数计数字节数从实体开始
ClosedChannelException
-如果这通道关闭
IllegalArgumentException
-如果新的位置是负的
IOException
-如果其他I/O错误发生
long size() throws IOException
ClosedChannelException
-如果这通道关闭
IOException
-如果其他I/O错误发生
SeekableByteChannel truncate(long size) throws IOException
如果给定的大小小于当前的大小,则实体被截断,丢弃新的结束后的任何字节。如果给定的大小大于或等于当前的大小,则实体不被修改。在这两种情况下,如果当前位置大于给定的大小,那么它被设置为该大小。
此接口的实现,可以禁止截断,当连接到一个实体,通常是一个文件,打开的APPEND
选项。
size
-新的大小,一个非负的字节数
NonWritableChannelException
-如果这个渠道没有打开写作
ClosedChannelException
-如果这通道关闭
IllegalArgumentException
-如果新的大小负
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.