37 |
|
|
38 |
package java.nio.channels; |
package java.nio.channels; |
39 |
|
|
40 |
import java.net.*; |
import java.io.IOException; |
41 |
import java.nio.*; |
import java.net.DatagramSocket; |
42 |
import java.nio.channels.spi.*; |
import java.net.SocketAddress; |
43 |
import java.io.*; |
import java.nio.ByteBuffer; |
44 |
|
import java.nio.channels.spi.AbstractSelectableChannel; |
|
|
|
45 |
|
|
46 |
public abstract class DatagramChannel |
public abstract class DatagramChannel |
47 |
extends AbstractSelectableChannel |
extends AbstractSelectableChannel |
48 |
implements ByteChannel, ScatteringByteChannel, GatheringByteChannel |
implements ByteChannel, ScatteringByteChannel, GatheringByteChannel |
49 |
{ |
{ |
50 |
protected DatagramChannel(SelectorProvider provider) |
protected DatagramChannel (SelectorProvider provider) |
51 |
{ |
{ |
52 |
} |
} |
53 |
|
|
54 |
public static DatagramChannel open() throws IOException |
public static DatagramChannel open () throws IOException |
55 |
{ |
{ |
56 |
return SelectorProvider.provider().openDatagramChannel(); |
return SelectorProvider.provider ().openDatagramChannel (); |
57 |
} |
} |
58 |
|
|
59 |
public long read(ByteBuffer[] dsts) |
public long read (ByteBuffer[] dsts) |
60 |
{ |
{ |
61 |
long b = 0; |
long b = 0; |
62 |
for (int i=0;i<dsts.length;i++) |
for (int i=0;i<dsts.length;i++) |
63 |
b += read(dsts[i]); |
b += read(dsts[i]); |
64 |
return b; |
return b; |
65 |
} |
} |
66 |
|
|
67 |
public abstract DatagramChannel connect(SocketAddress remote); |
public abstract DatagramChannel connect (SocketAddress remote); |
68 |
public abstract DatagramChannel disconnect(); |
public abstract DatagramChannel disconnect (); |
69 |
public abstract boolean isConnected(); |
public abstract boolean isConnected (); |
70 |
public abstract int read(ByteBuffer dst); |
public abstract int read (ByteBuffer dst); |
71 |
public abstract long read(ByteBuffer[] dsts, int offset, int length); |
public abstract long read (ByteBuffer[] dsts, int offset, int length); |
72 |
public abstract SocketAddress receive(ByteBuffer dst); |
public abstract SocketAddress receive (ByteBuffer dst); |
73 |
public abstract int send(ByteBuffer src, SocketAddress target); |
public abstract int send (ByteBuffer src, SocketAddress target); |
74 |
public abstract DatagramSocket socket(); |
public abstract DatagramSocket socket (); |
75 |
public abstract int write(ByteBuffer src); |
public abstract int write (ByteBuffer src); |
76 |
public abstract long write(ByteBuffer[] srcs, int offset, int length); |
public abstract long write (ByteBuffer[] srcs, int offset, int length); |
77 |
|
|
78 |
public int validOps() |
public int validOps() |
79 |
{ |
{ |
80 |
return SelectionKey.OP_READ | SelectionKey.OP_WRITE; |
return SelectionKey.OP_READ | SelectionKey.OP_WRITE; |
81 |
} |
} |
82 |
|
|
|
public int write(ByteBuffer[] dsts) |
|
|
{ |
|
|
long b = 0; |
|
|
for (int i=0;i<dsts.length;i++) |
|
|
b += write(dsts[i]); |
|
|
return (int)b; |
|
|
} |
|
83 |
} |
} |
|
|
|
|
|
|