ByteChannel
interface ByteChannel : ReadableByteChannel, WritableByteChannel
Known Direct Subclasses
DatagramChannel |
A selectable channel for datagram-oriented sockets.
|
SeekableByteChannel |
A byte channel that maintains a current position and allows the position to be changed.
|
SocketChannel |
A selectable channel for stream-oriented connecting sockets.
|
|
Known Indirect Subclasses
FileChannel |
A channel for reading, writing, mapping, and manipulating a file.
|
|
A channel that can read and write bytes. This interface simply unifies ReadableByteChannel
and WritableByteChannel
; it does not specify any new operations.
Summary
Inherited functions |
From class Channel
Unit |
close()
Closes this channel.
After a channel is closed, any further attempt to invoke I/O operations upon it will cause a ClosedChannelException to be thrown.
If this channel is already closed then invoking this method has no effect.
This method may be invoked at any time. If some other thread has already invoked it, however, then another invocation will block until the first invocation is complete, after which it will return without effect.
|
Unit |
close()
Closes this channel.
After a channel is closed, any further attempt to invoke I/O operations upon it will cause a ClosedChannelException to be thrown.
If this channel is already closed then invoking this method has no effect.
This method may be invoked at any time. If some other thread has already invoked it, however, then another invocation will block until the first invocation is complete, after which it will return without effect.
|
Boolean |
isOpen()
Tells whether or not this channel is open.
|
Boolean |
isOpen()
Tells whether or not this channel is open.
|
|
From class ReadableByteChannel
Int |
read(dst: ByteBuffer!)
Reads a sequence of bytes from this channel into the given buffer.
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.
Suppose that a byte sequence of length n is read, where 0 <= n <= r. This byte sequence will be transferred into the buffer so that the first byte in the sequence is at index p and the last byte is at index p + n - 1 , where p is the buffer's position at the moment this method is invoked. Upon return the buffer's position will be equal to p + n; its limit will not have changed.
A read operation might not fill the buffer, and in fact it might not read any bytes at all. Whether or not it does so depends upon the nature and state of the channel. A socket channel in non-blocking mode, for example, cannot read any more bytes than are immediately available from the socket's input buffer; similarly, a file channel cannot read any more bytes than remain in the file. It is guaranteed, however, that if a channel is in blocking mode and there is at least one byte remaining in the buffer then this method will block until at least one byte is read.
This method may be invoked at any time. If another thread has already initiated a read operation upon this channel, however, then an invocation of this method will block until the first operation is complete.
|
|
From class WritableByteChannel
Int |
write(src: ByteBuffer!)
Writes a sequence of bytes to this channel from the given buffer.
An attempt is made to write up to r bytes to the channel, where r is the number of bytes remaining in the buffer, that is, src.remaining() , at the moment this method is invoked.
Suppose that a byte sequence of length n is written, where 0 <= n <= r. This byte sequence will be transferred from the buffer starting at index p, where p is the buffer's position at the moment this method is invoked; the index of the last byte written will be p + n - 1 . Upon return the buffer's position will be equal to p + n; its limit will not have changed.
Unless otherwise specified, a write operation will return only after writing all of the r requested bytes. Some types of channels, depending upon their state, may write only some of the bytes or possibly none at all. A socket channel in non-blocking mode, for example, cannot write any more bytes than are free in the socket's output buffer.
This method may be invoked at any time. If another thread has already initiated a write operation upon this channel, however, then an invocation of this method will block until the first operation is complete.
|
|
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2023-03-08 UTC.
[null,null,["Last updated 2023-03-08 UTC."],[],[]]