java.nio.channels
public abstract class DatagramChannel extends AbstractSelectableChannel implements ByteChannel, ScatteringByteChannel, GatheringByteChannel
Modifier | Constructor and Description |
---|---|
protected |
DatagramChannel(SelectorProvider provider)
Initializes the channel.
|
Modifier and Type | Method and Description |
---|---|
abstract DatagramChannel |
connect(SocketAddress remote)
Connects this channel's socket.
|
abstract DatagramChannel |
disconnect()
Disonnects this channel's socket.
|
abstract boolean |
isConnected()
Tells whether or not this channel's socket is connected.
|
static DatagramChannel |
open()
Opens a datagram channel.
|
abstract int |
read(ByteBuffer dst)
Reads data from this channel.
|
long |
read(ByteBuffer[] dsts)
Reads data from this channel.
|
abstract long |
read(ByteBuffer[] dsts,
int offset,
int length)
Reads data from this channel.
|
abstract SocketAddress |
receive(ByteBuffer dst)
Receives a datagram via this channel.
|
abstract int |
send(ByteBuffer src,
SocketAddress target)
Sends a datagram via this channel.
|
abstract DatagramSocket |
socket()
Retrieves the channel's socket.
|
int |
validOps()
Retrieves the valid operations for this channel.
|
abstract int |
write(ByteBuffer src)
Writes data to this channel.
|
long |
write(ByteBuffer[] srcs)
Writes data to this channel.
|
abstract long |
write(ByteBuffer[] srcs,
int offset,
int length)
Writes data to this channel.
|
blockingLock, configureBlocking, implCloseChannel, implCloseSelectableChannel, implConfigureBlocking, isBlocking, isRegistered, keyFor, provider, register
register
begin, close, end, isOpen
protected DatagramChannel(SelectorProvider provider)
public static DatagramChannel open() throws IOException
IOException
- If an error occurspublic final long read(ByteBuffer[] dsts) throws IOException
read
in interface ScatteringByteChannel
AsynchronousCloseException
- If another thread closes this
channel while the write operation is in progressClosedByInterruptException
- If another thread interrupts the
current thread while the write operation is in progress, thereby closing
the channel and setting the current thread's interrupt statusClosedChannelException
- If this channel is closedIOException
- If an error occurspublic final long write(ByteBuffer[] srcs) throws IOException
write
in interface GatheringByteChannel
IOException
- If an error occursNotYetConnectedException
- The channel's socket is not connected.public abstract DatagramChannel connect(SocketAddress remote) throws IOException
AsynchronousCloseException
- If another thread closes this channel
while the connect operation is in progress.ClosedByInterruptException
- If another thread interrupts the
current thread while the read operation is in progress, thereby closing the
channel and setting the current thread's interrupt status.ClosedChannelException
- If this channel is closed.IOException
- If an error occurs.SecurityException
- If a security manager has been installed and
it does not permit datagrams to be sent to the given address.public abstract DatagramChannel disconnect() throws IOException
IOException
- If an error occurspublic abstract boolean isConnected()
NotYetConnectedException
- The channel's socket is not connected.public abstract int read(ByteBuffer dst) throws IOException
read
in interface ReadableByteChannel
dst
- the buffer to put the read data intoAsynchronousCloseException
- If another thread closes this
channel while the read operation is in progressClosedByInterruptException
- If another thread interrupts the
current thread while the read operation is in progress, thereby closing
the channel and setting the current thread's interrupt statusClosedChannelException
- If this channel is closedIOException
- If an error occurspublic abstract long read(ByteBuffer[] dsts, int offset, int length) throws IOException
read
in interface ScatteringByteChannel
IOException
- If an error occurs.NotYetConnectedException
- The channel's socket is not connected.public abstract SocketAddress receive(ByteBuffer dst) throws IOException
AsynchronousCloseException
- If another thread closes this channel
while the connect operation is in progress.ClosedByInterruptException
- If another thread interrupts the
current thread while the read operation is in progress, thereby closing the
channel and setting the current thread's interrupt status.ClosedChannelException
- If this channel is closed.IOException
- If an error occursSecurityException
- If a security manager has been installed and
it does not permit datagrams to be sent to the given address.public abstract int send(ByteBuffer src, SocketAddress target) throws IOException
AsynchronousCloseException
- If another thread closes this channel
while the connect operation is in progress.ClosedByInterruptException
- If another thread interrupts the
current thread while the read operation is in progress, thereby closing the
channel and setting the current thread's interrupt status.ClosedChannelException
- If this channel is closed.IOException
- If an error occursSecurityException
- If a security manager has been installed and
it does not permit datagrams to be sent to the given address.public abstract DatagramSocket socket()
public abstract int write(ByteBuffer src) throws IOException
write
in interface WritableByteChannel
IOException
- If an error occurs.NotYetConnectedException
- The channel's socket is not connected.public abstract long write(ByteBuffer[] srcs, int offset, int length) throws IOException
write
in interface GatheringByteChannel
IOException
- If an error occurs.NotYetConnectedException
- The channel's socket is not connected.public final int validOps()
validOps
in class SelectableChannel
NotYetConnectedException
- The channel's socket is not connected.