1 7 8 package java.nio.channels; 9 10 import java.io.IOException ; 11 import java.net.Socket ; 12 import java.net.SocketAddress ; 13 import java.nio.ByteBuffer ; 14 import java.nio.channels.spi.*; 15 16 17 78 79 public abstract class SocketChannel 80 extends AbstractSelectableChannel 81 implements ByteChannel , ScatteringByteChannel , GatheringByteChannel 82 { 83 84 87 protected SocketChannel(SelectorProvider provider) { 88 super(provider); 89 } 90 91 104 public static SocketChannel open() throws IOException { 105 return SelectorProvider.provider().openSocketChannel(); 106 } 107 108 142 public static SocketChannel open(SocketAddress remote) 143 throws IOException 144 { 145 SocketChannel sc = open(); 146 sc.connect(remote); 147 return sc; 148 } 149 150 161 public final int validOps() { 162 return (SelectionKey.OP_READ 163 | SelectionKey.OP_WRITE 164 | SelectionKey.OP_CONNECT); 165 } 166 167 168 170 178 public abstract Socket socket(); 179 180 186 public abstract boolean isConnected(); 187 188 196 public abstract boolean isConnectionPending(); 197 198 265 public abstract boolean connect(SocketAddress remote) throws IOException ; 266 267 316 public abstract boolean finishConnect() throws IOException ; 317 318 319 321 325 public abstract int read(ByteBuffer dst) throws IOException ; 326 327 331 public abstract long read(ByteBuffer [] dsts, int offset, int length) 332 throws IOException ; 333 334 338 public final long read(ByteBuffer [] dsts) throws IOException { 339 return read(dsts, 0, dsts.length); 340 } 341 342 346 public abstract int write(ByteBuffer src) throws IOException ; 347 348 352 public abstract long write(ByteBuffer [] srcs, int offset, int length) 353 throws IOException ; 354 355 359 public final long write(ByteBuffer [] srcs) throws IOException { 360 return write(srcs, 0, srcs.length); 361 } 362 363 } 364 | Popular Tags |