java.nio.channels
Class DatagramChannel

java.lang.Object
  extended by java.nio.channels.spi.AbstractInterruptibleChannel
      extended by java.nio.channels.SelectableChannel
          extended by java.nio.channels.spi.AbstractSelectableChannel
              extended by java.nio.channels.DatagramChannel
All Implemented Interfaces:
Closeable, ByteChannel, Channel, GatheringByteChannel, InterruptibleChannel, ReadableByteChannel, ScatteringByteChannel, WritableByteChannel

public abstract class DatagramChannel
extends AbstractSelectableChannel
implements ByteChannel, ScatteringByteChannel, GatheringByteChannel

Since:
1.4

Constructor Summary
protected DatagramChannel(SelectorProvider provider)
          Initializes the channel.
 
Method Summary
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.
 
Methods inherited from class java.nio.channels.spi.AbstractSelectableChannel
blockingLock, configureBlocking, implCloseChannel, implCloseSelectableChannel, implConfigureBlocking, isBlocking, isRegistered, keyFor, provider, register
 
Methods inherited from class java.nio.channels.SelectableChannel
register
 
Methods inherited from class java.nio.channels.spi.AbstractInterruptibleChannel
begin, close, end, isOpen
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.nio.channels.Channel
close, isOpen
 

Constructor Detail

DatagramChannel

protected DatagramChannel(SelectorProvider provider)
Initializes the channel.

Method Detail

open

public static DatagramChannel open()
                            throws IOException
Opens a datagram channel.

Throws:
IOException - If an error occurs

read

public final long read(ByteBuffer[] dsts)
                throws IOException
Reads data from this channel.

Specified by:
read in interface ScatteringByteChannel
Throws:
AsynchronousCloseException - If another thread closes this channel while the write operation is in progress
ClosedByInterruptException - 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 status
ClosedChannelException - If this channel is closed
IOException - If an error occurs

write

public final long write(ByteBuffer[] srcs)
                 throws IOException
Writes data to this channel.

Specified by:
write in interface GatheringByteChannel
Throws:
IOException - If an error occurs
NotYetConnectedException - The channel's socket is not connected.

connect

public abstract DatagramChannel connect(SocketAddress remote)
                                 throws IOException
Connects this channel's socket.

Throws:
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.

disconnect

public abstract DatagramChannel disconnect()
                                    throws IOException
Disonnects this channel's socket.

Throws:
IOException - If an error occurs

isConnected

public abstract boolean isConnected()
Tells whether or not this channel's socket is connected.

Throws:
NotYetConnectedException - The channel's socket is not connected.

read

public abstract int read(ByteBuffer dst)
                  throws IOException
Reads data from this channel.

Specified by:
read in interface ReadableByteChannel
Parameters:
dst - the buffer to put the read data into
Returns:
the numer of bytes read
Throws:
AsynchronousCloseException - If another thread closes this channel while the read 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

read

public abstract long read(ByteBuffer[] dsts,
                          int offset,
                          int length)
                   throws IOException
Reads data from this channel.

Specified by:
read in interface ScatteringByteChannel
Throws:
IOException - If an error occurs.
NotYetConnectedException - The channel's socket is not connected.

receive

public abstract SocketAddress receive(ByteBuffer dst)
                               throws IOException
Receives a datagram via this channel.

Throws:
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.

send

public abstract int send(ByteBuffer src,
                         SocketAddress target)
                  throws IOException
Sends a datagram via this channel.

Throws:
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.

socket

public abstract DatagramSocket socket()
Retrieves the channel's socket.


write

public abstract int write(ByteBuffer src)
                   throws IOException
Writes data to this channel.

Specified by:
write in interface WritableByteChannel
Throws:
IOException - If an error occurs.
NotYetConnectedException - The channel's socket is not connected.

write

public abstract long write(ByteBuffer[] srcs,
                           int offset,
                           int length)
                    throws IOException
Writes data to this channel.

Specified by:
write in interface GatheringByteChannel
Throws:
IOException - If an error occurs.
NotYetConnectedException - The channel's socket is not connected.

validOps

public final int validOps()
Retrieves the valid operations for this channel.

Specified by:
validOps in class SelectableChannel
Throws:
NotYetConnectedException - The channel's socket is not connected.