Java Doc for DatagramChannel.java in  » Apache-Harmony-Java-SE » java-package » java » nio » channels » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » java package » java.nio.channels 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.nio.channels.SelectableChannel
   java.nio.channels.spi.AbstractSelectableChannel
      java.nio.channels.DatagramChannel

DatagramChannel
abstract public class DatagramChannel extends AbstractSelectableChannel implements ByteChannel,ScatteringByteChannel,GatheringByteChannel(Code)
A DatagramChannel is a selectable channel for part abstraction of datagram socket. The socket method of this class can return the related DatagramSocket instance, which can handle the socket.

A datagram channel is open but not connected when created by open method. After connected, it will keep the connected status before disconnecting or closing. The benefit of a connected channel is the reduced effort of security checks during send and receive. When invoking read or write, a connected channel is required.

Datagram channels are thread-safe, no more than one thread can read or write at given time.




Constructor Summary
protected  DatagramChannel(SelectorProvider selectorProvider)
     Constructor for this class.

Method Summary
abstract public  DatagramChannelconnect(SocketAddress address)
     Connect the socket of this channel to a remote address, which is the only communication peer of getting and sending datagrams after connected.

This method can be called at any moment, and won't affect the processing read and write operation.

abstract public  DatagramChanneldisconnect()
     Disconnect the socket of this channel, which is connected before for getting and sending datagrams.

This method can be called at any moment, and won't affect the processing read and write operation.

abstract public  booleanisConnected()
     Answer whether this channel's socket is connected or not.
public static  DatagramChannelopen()
     Create a open and not-connected datagram channel.
abstract public  intread(ByteBuffer target)
     Reads datagram from the channel into the byte buffer.

The precondition of calling this method is that the channel is connected and the coming datagram is from the connected address.

abstract public  longread(ByteBuffer[] targets, int offset, int length)
     Reads datagram from the channel into the byte buffer.

The precondition of calling this method is that the channel is connected and the coming datagram is from the connected address.

final public synchronized  longread(ByteBuffer[] targets)
     Reads datagram from the channel into the byte buffer.

The precondition of calling this method is that the channel is connected and the coming datagram is from the connected address.

abstract public  SocketAddressreceive(ByteBuffer target)
     Get a datagram from this channel.

This method transfers the datagram from the channel into the target byte buffer and return the address of the datagram, if the datagram is available or will be available as this channel is in blocking mode.

abstract public  intsend(ByteBuffer source, SocketAddress address)
     Sends out a datagram by the channel.

The precondition of sending is that whether the channel is in blocking mode and enough byte buffer space will be available, or the channel is in non-blocking mode and byte buffer space is enough.

abstract public  DatagramSocketsocket()
     Return the related datagram socket of this channel, which won't declare public methods that not declared in DatagramSocket.
final public  intvalidOps()
     Get the valid operations of this channel.
abstract public  intwrite(ByteBuffer source)
     Write datagram from the byte buffer into the channel.

The precondition of calling this method is that the channel is connected and the datagram is sent to the connected address.

abstract public  longwrite(ByteBuffer[] sources, int offset, int length)
     Write datagram from the byte buffer into the channel.

The precondition of calling this method is that the channel is connected and the datagram is sent to the connected address.

final public synchronized  longwrite(ByteBuffer[] sources)
     Write datagram from the byte buffer into the channel.

The precondition of calling this method is that the channel is connected and the datagram is sent to the connected address.



Constructor Detail
DatagramChannel
protected DatagramChannel(SelectorProvider selectorProvider)(Code)
Constructor for this class.
Parameters:
  selectorProvider - A instance of SelectorProvider




Method Detail
connect
abstract public DatagramChannel connect(SocketAddress address) throws IOException(Code)
Connect the socket of this channel to a remote address, which is the only communication peer of getting and sending datagrams after connected.

This method can be called at any moment, and won't affect the processing read and write operation. The connect status won't changed before disconnected and closed.

This method just execute the same security checks as the connect method of the DatagramSocket class.


Parameters:
  address - The address to be connected. This channel.
throws:
  ClosedChannelException - If the channel is already closed.
throws:
  AsynchronousCloseException - If the channel is closed by another thread while this methodis in operation.
throws:
  ClosedByInterruptException - If another thread interrupts the calling thread while theoperation is in progress. The calling thread will have theinterrupt state set, and the channel will be closed.
throws:
  SecurityException - If there is a security manager, and the address is notpermitted to access.
throws:
  IOException - Some other IO error occurred.



disconnect
abstract public DatagramChannel disconnect() throws IOException(Code)
Disconnect the socket of this channel, which is connected before for getting and sending datagrams.

This method can be called at any moment, and won't affect the processing read and write operation. It won't has any effect if the socket is not connected or the channel is closed.

This channel.
throws:
  IOException - Some other IO error occurred.



isConnected
abstract public boolean isConnected()(Code)
Answer whether this channel's socket is connected or not. true for this channel's socket is connected;false otherwise.



open
public static DatagramChannel open() throws IOException(Code)
Create a open and not-connected datagram channel.

This channel is got by openDatagramChannel method of the default SelectorProvider instance.

The new created channel which is open but not-connected.
throws:
  IOException - If some IO problem occurs.



read
abstract public int read(ByteBuffer target) throws IOException(Code)
Reads datagram from the channel into the byte buffer.

The precondition of calling this method is that the channel is connected and the coming datagram is from the connected address. If the buffer is not enough to store the datagram, the residual part of the datagram is ignored. Otherwise, this method has the same behavior as the read method in the ReadableByteChannel interface.


See Also:   java.nio.channels.ReadableByteChannel.read(java.nio.ByteBuffer)
Parameters:
  target - The byte buffer to store the received datagram. Non-negative number as the number of bytes read, or -1 as theread operation reaches the end of stream.
throws:
  NotYetConnectedException - If the channel is not connected yet.
throws:
  ClosedChannelException - If the channel is already closed.
throws:
  AsynchronousCloseException - If the channel is closed by another thread while this methodis in operation.
throws:
  ClosedByInterruptException - If another thread interrupts the calling thread while theoperation is in progress. The calling thread will have theinterrupt state set, and the channel will be closed.
throws:
  IOException - Some other IO error occurred.



read
abstract public long read(ByteBuffer[] targets, int offset, int length) throws IOException(Code)
Reads datagram from the channel into the byte buffer.

The precondition of calling this method is that the channel is connected and the coming datagram is from the connected address. If the buffer is not enough to store the datagram, the residual part of the datagram is ignored. Otherwise, this method has the same behavior as the read method in the ScatteringByteChannel interface.


See Also:   java.nio.channels.ScatteringByteChannel.read(java.nio.ByteBuffer[]intint)
Parameters:
  targets - The byte buffers to store the received datagram.
Parameters:
  offset - A non-negative offset in the array of buffer, pointing to thestarting buffer to store the byte transferred, must no largerthan targets.length.
Parameters:
  length - A non-negative length to indicate the maximum number of byteto be read, must no larger than targets.length - offset. Non-negative number as the number of bytes read, or -1 as theread operation reaches the end of stream.
throws:
  NotYetConnectedException - If the channel is not connected yet.
throws:
  ClosedChannelException - If the channel is already closed.
throws:
  AsynchronousCloseException - If the channel is closed by another thread while this methodis in operation.
throws:
  ClosedByInterruptException - If another thread interrupts the calling thread while theoperation is in progress. The calling thread will have theinterrupt state set, and the channel will be closed.
throws:
  IOException - Some other IO error occurred.



read
final public synchronized long read(ByteBuffer[] targets) throws IOException(Code)
Reads datagram from the channel into the byte buffer.

The precondition of calling this method is that the channel is connected and the coming datagram is from the connected address. If the buffer is not enough to store the datagram, the residual part of the datagram is ignored. Otherwise, this method has the same behavior as the read method in the ScatteringByteChannel interface.


See Also:   java.nio.channels.ScatteringByteChannel.read(java.nio.ByteBuffer[])
Parameters:
  targets - The byte buffers to store the received datagram. Non-negative number as the number of bytes read, or -1 as theread operation reaches the end of stream.
throws:
  NotYetConnectedException - If the channel is not connected yet.
throws:
  ClosedChannelException - If the channel is already closed.
throws:
  AsynchronousCloseException - If the channel is closed by another thread while this methodis in operation.
throws:
  ClosedByInterruptException - If another thread interrupts the calling thread while theoperation is in progress. The calling thread will have theinterrupt state set, and the channel will be closed.
throws:
  IOException - Some other IO error occurred.



receive
abstract public SocketAddress receive(ByteBuffer target) throws IOException(Code)
Get a datagram from this channel.

This method transfers the datagram from the channel into the target byte buffer and return the address of the datagram, if the datagram is available or will be available as this channel is in blocking mode. This method returns null if the datagram is not available now and the channel is in non-blocking mode. The transfer start at the current position of the buffer, and the residual part of the datagram will be ignored if there is no efficient remaining in the buffer to store the datagram.

This method can be called at any moment, and will block if there is another thread started a read operation on the channel.

This method just execute the same security checks as the receive method of the DatagramSocket class.


Parameters:
  target - The byte buffer to store the received datagram. Address of the datagram if the transfer is performed, or null ifthe channel is in non-blocking mode and the datagram areunavailable.
throws:
  ClosedChannelException - If the channel is already closed.
throws:
  AsynchronousCloseException - If the channel is closed by another thread while this methodis in operation.
throws:
  ClosedByInterruptException - If another thread interrupts the calling thread while theoperation is in progress. The calling thread will have theinterrupt state set, and the channel will be closed.
throws:
  SecurityException - If there is a security manager, and the address is notpermitted to access.
throws:
  IOException - Some other IO error occurred.



send
abstract public int send(ByteBuffer source, SocketAddress address) throws IOException(Code)
Sends out a datagram by the channel.

The precondition of sending is that whether the channel is in blocking mode and enough byte buffer space will be available, or the channel is in non-blocking mode and byte buffer space is enough. The transfer action is just like a regular write operation.

This method can be called at any moment, and will block if there is another thread started a read operation on the channel.

This method just execute the same security checks as the send method of the DatagramSocket class.


Parameters:
  source - The byte buffer with the datagram to be sent.
Parameters:
  address - The address to be sent. The number of sent bytes. If this method is called, it returnsthe number of bytes that remaining in the byte buffer. If thechannel is in non-blocking mode and no enough space for thedatagram in the buffer, it may returns zero.
throws:
  ClosedChannelException - If the channel is already closed.
throws:
  AsynchronousCloseException - If the channel is closed by another thread while this methodis in operation.
throws:
  ClosedByInterruptException - If another thread interrupts the calling thread while theoperation is in progress. The calling thread will have theinterrupt state set, and the channel will be closed.
throws:
  SecurityException - If there is a security manager, and the address is notpermitted to access.
throws:
  IOException - Some other IO error occurred.



socket
abstract public DatagramSocket socket()(Code)
Return the related datagram socket of this channel, which won't declare public methods that not declared in DatagramSocket. The related DatagramSocket instance.



validOps
final public int validOps()(Code)
Get the valid operations of this channel. Datagram channels support read and write operation, so this method returns ( SelectionKey.OP_READ | SelectionKey.OP_WRITE ).
See Also:   java.nio.channels.SelectableChannel.validOps Valid operations in bit-set.



write
abstract public int write(ByteBuffer source) throws IOException(Code)
Write datagram from the byte buffer into the channel.

The precondition of calling this method is that the channel is connected and the datagram is sent to the connected address. Otherwise, this method has the same behavior as the write method in the WritableByteChannel interface.


See Also:   java.nio.channels.WritableByteChannel.write(java.nio.ByteBuffer)
Parameters:
  source - The byte buffer as the source of the datagram. Non-negative number of bytes written.
throws:
  NotYetConnectedException - If the channel is not connected yet.
throws:
  ClosedChannelException - If the channel is already closed.
throws:
  AsynchronousCloseException - If the channel is closed by another thread while this methodis in operation.
throws:
  ClosedByInterruptException - If another thread interrupts the calling thread while theoperation is in progress. The calling thread will have theinterrupt state set, and the channel will be closed.
throws:
  IOException - Some other IO error occurred.



write
abstract public long write(ByteBuffer[] sources, int offset, int length) throws IOException(Code)
Write datagram from the byte buffer into the channel.

The precondition of calling this method is that the channel is connected and the datagram is sent to the connected address. Otherwise, this method has the same behavior as the write method in the GatheringByteChannel interface.
See Also:   java.nio.channels.GatheringByteChannel.write(java.nio.ByteBuffer[]intint)
Parameters:
  sources - The byte buffers as the source of the datagram.
Parameters:
  offset - A non-negative offset in the array of buffer, pointing to thestarting buffer to be retrieved, must no larger thansources.length.
Parameters:
  length - A non-negative length to indicate the maximum number of byteto be written, must no larger than sources.length - offset. The number of written bytes. If this method is called, it returnsthe number of bytes that remaining in the byte buffer. If thechannel is in non-blocking mode and no enough space for thedatagram in the buffer, it may returns zero.
throws:
  NotYetConnectedException - If the channel is not connected yet.
throws:
  ClosedChannelException - If the channel is already closed.
throws:
  AsynchronousCloseException - If the channel is closed by another thread while this methodis in operation.
throws:
  ClosedByInterruptException - If another thread interrupts the calling thread while theoperation is in progress. The calling thread will have theinterrupt state set, and the channel will be closed.
throws:
  IOException - Some other IO error occurred.




write
final public synchronized long write(ByteBuffer[] sources) throws IOException(Code)
Write datagram from the byte buffer into the channel.

The precondition of calling this method is that the channel is connected and the datagram is sent to the connected address. Otherwise, this method has the same behavior as the write method in the GatheringByteChannel interface.
See Also:   java.nio.channels.GatheringByteChannel.write(java.nio.ByteBuffer[])
Parameters:
  sources - The byte buffers as the source of the datagram. The number of written bytes. If this method is called, it returnsthe number of bytes that remaining in the byte buffer. If thechannel is in non-blocking mode and no enough space for thedatagram in the buffer, it may returns zero.
throws:
  NotYetConnectedException - If the channel is not connected yet.
throws:
  ClosedChannelException - If the channel is already closed.
throws:
  AsynchronousCloseException - If the channel is closed by another thread while this methodis in operation.
throws:
  ClosedByInterruptException - If another thread interrupts the calling thread while theoperation is in progress. The calling thread will have theinterrupt state set, and the channel will be closed.
throws:
  IOException - Some other IO error occurred.




Methods inherited from java.nio.channels.spi.AbstractSelectableChannel
final public Object blockingLock()(Code)(Java Doc)
final public SelectableChannel configureBlocking(boolean blockingMode) throws IOException(Code)(Java Doc)
final protected synchronized void implCloseChannel() throws IOException(Code)(Java Doc)
abstract protected void implCloseSelectableChannel() throws IOException(Code)(Java Doc)
abstract protected void implConfigureBlocking(boolean blockingMode) throws IOException(Code)(Java Doc)
final public boolean isBlocking()(Code)(Java Doc)
final public synchronized boolean isRegistered()(Code)(Java Doc)
final public synchronized SelectionKey keyFor(Selector selector)(Code)(Java Doc)
final public SelectorProvider provider()(Code)(Java Doc)
final public SelectionKey register(Selector selector, int interestSet, Object attachment) throws ClosedChannelException(Code)(Java Doc)

Methods inherited from java.nio.channels.SelectableChannel
abstract public Object blockingLock()(Code)(Java Doc)
abstract public SelectableChannel configureBlocking(boolean block) throws IOException(Code)(Java Doc)
abstract public boolean isBlocking()(Code)(Java Doc)
abstract public boolean isRegistered()(Code)(Java Doc)
abstract public SelectionKey keyFor(Selector sel)(Code)(Java Doc)
abstract public SelectorProvider provider()(Code)(Java Doc)
final public SelectionKey register(Selector selector, int operations) throws ClosedChannelException(Code)(Java Doc)
abstract public SelectionKey register(Selector sel, int ops, Object att) throws ClosedChannelException(Code)(Java Doc)
abstract public int validOps()(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.