1 22 23 package org.xsocket.stream; 24 25 import java.io.Closeable ; 26 import java.io.Flushable ; 27 import java.io.IOException ; 28 import java.io.UnsupportedEncodingException ; 29 import java.net.InetAddress ; 30 import java.nio.ByteBuffer ; 31 import java.nio.channels.GatheringByteChannel ; 32 import java.nio.channels.ReadableByteChannel ; 33 import java.nio.channels.WritableByteChannel ; 34 import java.util.Map ; 35 36 import org.xsocket.ClosedConnectionException; 37 import org.xsocket.IDataSink; 38 import org.xsocket.IDataSource; 39 import org.xsocket.MaxReadSizeExceededException; 40 41 42 43 48 public interface IConnection extends IDataSource, IDataSink, GatheringByteChannel , ReadableByteChannel , WritableByteChannel , Flushable , Closeable { 49 50 public static final String INITIAL_DEFAULT_ENCODING = "UTF-8"; 51 public static final boolean INITIAL_AUTOFLUSH = true; 52 53 public static final String SO_SNDBUF = "SOL_SOCKET.SO_SNDBUF"; 54 public static final String SO_RCVBUF = "SOL_SOCKET.SO_RCVBUF"; 55 public static final String SO_REUSEADDR = "SOL_SOCKET.SO_REUSEADDR"; 56 public static final String SO_KEEPALIVE = "SOL_SOCKET.SO_KEEPALIVE"; 57 public static final String SO_LINGER = "SOL_SOCKET.SO_LINGER"; 58 public static final String TCP_NODELAY = "IPPROTO_TCP.TCP_NODELAY"; 59 60 61 public enum FlushMode { SYNC, ASYNC }; 62 63 64 69 public String getId(); 70 71 72 82 public boolean isOpen(); 83 84 85 91 public void flush() throws ClosedConnectionException, IOException ; 92 93 94 95 100 public int getLocalPort(); 101 102 103 104 109 public InetAddress getLocalAddress(); 110 111 112 113 114 119 public InetAddress getRemoteAddress(); 120 121 122 127 public int getRemotePort(); 128 129 130 135 public void setDefaultEncoding(String encoding); 136 137 138 143 public void suspendRead() throws IOException ; 144 145 146 151 public void resumeRead() throws IOException ; 152 153 154 159 public String getDefaultEncoding(); 160 161 162 163 171 public void setAutoflush(boolean autoflush); 172 173 174 175 179 public boolean getAutoflush(); 180 181 182 183 184 189 public int getIdleTimeoutSec(); 190 191 192 193 194 195 196 201 public void setIdleTimeoutSec(int timeoutInSec); 202 203 204 205 210 public int getConnectionTimeoutSec(); 211 212 213 220 public void setConnectionTimeoutSec(int timeoutSec); 221 222 223 224 230 public int getPendingWriteDataSize(); 231 232 233 234 241 public void activateSecuredMode() throws IOException ; 242 243 244 253 public int write(String message, String encoding) throws ClosedConnectionException, IOException ; 254 255 256 264 public int write(String message) throws ClosedConnectionException, IOException ; 265 266 267 275 public int write(byte b) throws ClosedConnectionException, IOException ; 276 277 278 286 public int write(byte... bytes) throws ClosedConnectionException, IOException ; 287 288 289 299 public int write(byte[] bytes, int offset, int length) throws ClosedConnectionException, IOException ; 300 301 302 314 public int write(ByteBuffer buffer) throws ClosedConnectionException, IOException ; 315 316 317 329 public long write(ByteBuffer [] buffers) throws ClosedConnectionException, IOException ; 330 331 332 340 public int write(int i) throws ClosedConnectionException, IOException ; 341 342 343 351 public int write(long l) throws ClosedConnectionException, IOException ; 352 353 354 362 public int write(double d) throws ClosedConnectionException, IOException ; 363 364 365 372 public byte readByte() throws IOException , ClosedConnectionException; 373 374 375 382 public int readInt() throws IOException , ClosedConnectionException; 383 384 385 392 public long readLong() throws IOException , ClosedConnectionException; 393 394 395 402 public double readDouble() throws IOException , ClosedConnectionException; 403 404 405 417 public ByteBuffer [] readByteBufferByDelimiter(String delimiter) throws IOException , ClosedConnectionException; 418 419 420 421 434 public ByteBuffer [] readByteBufferByDelimiter(String delimiter, int maxLength) throws IOException , ClosedConnectionException, MaxReadSizeExceededException; 435 436 437 438 452 public ByteBuffer [] readByteBufferByDelimiter(String delimiter, String encoding, int maxLength) throws IOException , ClosedConnectionException, MaxReadSizeExceededException; 453 454 455 466 public ByteBuffer [] readByteBufferByLength(int length) throws IOException , ClosedConnectionException; 467 468 469 481 public byte[] readBytesByDelimiter(String delimiter) throws IOException , ClosedConnectionException; 482 483 484 485 498 public byte[] readBytesByDelimiter(String delimiter, int maxLength) throws IOException , ClosedConnectionException, MaxReadSizeExceededException; 499 500 501 502 516 public byte[] readBytesByDelimiter(String delimiter, String encoding, int maxLength) throws IOException , ClosedConnectionException, MaxReadSizeExceededException; 517 518 519 530 public byte[] readBytesByLength(int length) throws IOException , ClosedConnectionException; 531 532 533 534 545 public String readStringByDelimiter(String delimiter) throws IOException , ClosedConnectionException, UnsupportedEncodingException ; 546 547 548 549 550 562 public String readStringByDelimiter(String delimiter, int maxLength) throws IOException , ClosedConnectionException, UnsupportedEncodingException , MaxReadSizeExceededException; 563 564 565 566 575 public String readStringByLength(int length) throws IOException , ClosedConnectionException, UnsupportedEncodingException ; 576 577 578 590 public String readStringByDelimiter(String delimiter, String encoding) throws IOException , ClosedConnectionException, UnsupportedEncodingException ; 591 592 593 606 public String readStringByDelimiter(String delimiter, String encoding, int maxLength) throws IOException , ClosedConnectionException, UnsupportedEncodingException , MaxReadSizeExceededException; 607 608 609 619 public String readStringByLength(int length, String encoding) throws IOException , ClosedConnectionException, UnsupportedEncodingException ; 620 621 622 623 632 public int getIndexOf(String str) throws IOException , ClosedConnectionException; 633 634 635 636 637 648 public int getIndexOf(String str, int maxLength) throws IOException , ClosedConnectionException, MaxReadSizeExceededException; 649 650 651 652 664 public int getIndexOf(String str, String encoding, int maxLength) throws IOException , ClosedConnectionException, MaxReadSizeExceededException; 665 666 667 690 public void markWritePosition(); 691 692 693 696 public void removeWriteMark(); 697 698 699 705 public boolean resetToWriteMark(); 706 707 708 713 public void markReadPosition(); 714 715 716 719 public void removeReadMark(); 720 721 722 728 public boolean resetToReadMark(); 729 730 731 732 738 public Object attach(Object obj); 739 740 741 746 public Object attachment(); 747 748 749 750 758 public IConnection setOption(String name, Object value) throws IOException ; 759 760 761 762 769 public Object getOption(String name) throws IOException ; 770 771 772 773 781 public Map <String ,Class > getOptions(); 782 } 783 | Popular Tags |