org.xsocket.stream
Interface IConnection

Package class diagram package IConnection
All Superinterfaces:
java.nio.channels.Channel, java.io.Closeable, java.io.Flushable, java.nio.channels.GatheringByteChannel, IDataSink, IDataSource, java.nio.channels.ReadableByteChannel, java.nio.channels.WritableByteChannel
All Known Subinterfaces:
IBlockingConnection, INonBlockingConnection
All Known Implementing Classes:
BlockingConnection, NonBlockingConnection

public interface IConnection
extends IDataSource, IDataSink, java.nio.channels.GatheringByteChannel, java.nio.channels.ReadableByteChannel, java.nio.channels.WritableByteChannel, java.io.Flushable, java.io.Closeable

A connection (session) between two endpoints. It encapsulates the underlying socket channel.


Nested Class Summary
static class IConnection.FlushMode
           
 
Field Summary
static boolean INITIAL_AUTOFLUSH
           
static java.lang.String INITIAL_DEFAULT_ENCODING
           
static java.lang.String SO_KEEPALIVE
           
static java.lang.String SO_LINGER
           
static java.lang.String SO_RCVBUF
           
static java.lang.String SO_REUSEADDR
           
static java.lang.String SO_SNDBUF
           
static java.lang.String TCP_NODELAY
           
 
Method Summary
 void activateSecuredMode()
          ad hoc activation of a secured mode (SSL).
 java.lang.Object attach(java.lang.Object obj)
          Deprecated. use setAttachment(Object) instead
 java.lang.Object attachment()
          Deprecated. use getAttachment() instead
 void flush()
          flush the send buffer.
 java.lang.Object getAttachment()
          Retrieves the current attachment.
 boolean getAutoflush()
          get autoflush
 int getConnectionTimeoutSec()
          gets the connection timeout
 java.lang.String getDefaultEncoding()
          gets the default encoding for this connection (used by string related methods like readString...)
 java.lang.String getId()
          returns the id
 int getIdleTimeoutSec()
          returns the idle timeout in sec.
 int getIndexOf(java.lang.String str)
          Returns the index of the first occurrence of the given string.
 int getIndexOf(java.lang.String str, int maxLength)
          Returns the index of the first occurrence of the given string.
 int getIndexOf(java.lang.String str, java.lang.String encoding, int maxLength)
          Returns the index of the first occurrence of the given string.
 java.net.InetAddress getLocalAddress()
          returns the local address
 int getLocalPort()
          returns the local port
 java.lang.Object getOption(java.lang.String name)
          returns the value of a option
 java.util.Map<java.lang.String,java.lang.Class> getOptions()
          Returns an unmodifiable map of the options supported by this endpoint.
 int getPendingWriteDataSize()
          returns the size of the data which have already been written, but not yet transferred to the underlying socket.
 java.net.InetAddress getRemoteAddress()
          returns the remote address
 int getRemotePort()
          returns the port of the remote endpoint
 boolean isOpen()
          returns, if the connection is open.
 void markReadPosition()
          Marks the present read position in the connection.
 void markWritePosition()
          Marks the present write position in the connection.
 byte readByte()
          read a byte
 java.nio.ByteBuffer[] readByteBufferByDelimiter(java.lang.String delimiter)
          read a ByteBuffer by using a delimiter.
 java.nio.ByteBuffer[] readByteBufferByDelimiter(java.lang.String delimiter, int maxLength)
          read a ByteBuffer by using a delimiter.
 java.nio.ByteBuffer[] readByteBufferByDelimiter(java.lang.String delimiter, java.lang.String encoding, int maxLength)
          read a ByteBuffer by using a delimiter For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes
 java.nio.ByteBuffer[] readByteBufferByLength(int length)
          read a ByteBuffer by using a length defintion For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes
 byte[] readBytesByDelimiter(java.lang.String delimiter)
          read a byte array by using a delimiter. readByteBufferByDelimiter(String, int) To avoid memory leaks the readBytesByDelimiter(String, int) method is generally preferable
For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes
 byte[] readBytesByDelimiter(java.lang.String delimiter, int maxLength)
          read a byte array by using a delimiter. readByteBufferByDelimiter(String, int) For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes
 byte[] readBytesByDelimiter(java.lang.String delimiter, java.lang.String encoding, int maxLength)
          read a byte array by using a delimiter For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes
 byte[] readBytesByLength(int length)
          read bytes by using a length defintion For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes
 double readDouble()
          read a double
 int readInt()
          read an int
 long readLong()
          read a long
 java.lang.String readStringByDelimiter(java.lang.String delimiter)
          read a string by using a delimiter and the connection default encoding To avoid memory leaks the readStringByDelimiter(String, int) method is generally preferable
 java.lang.String readStringByDelimiter(java.lang.String delimiter, int maxLength)
          read a string by using a delimiter and the connection default encoding
 java.lang.String readStringByDelimiter(java.lang.String delimiter, java.lang.String encoding)
          read a string by using a delimiter To avoid memory leaks the readStringByDelimiter(String, String, int) method is generally preferable
 java.lang.String readStringByDelimiter(java.lang.String delimiter, java.lang.String encoding, int maxLength)
          read a string by using a delimiter
 java.lang.String readStringByLength(int length)
          read a string by using a length definition and the connection default encoding
 java.lang.String readStringByLength(int length, java.lang.String encoding)
          read a string by using a length definition
 void removeReadMark()
          remove the mark the present read position in the connection.
 void removeWriteMark()
          remove the mark the present write position in the connection.
 boolean resetToReadMark()
          Resets to the marked read position.
 boolean resetToWriteMark()
          Resets to the marked write position.
 void resumeRead()
          resume reading data from the underlying subsystem
 void setAttachment(java.lang.Object obj)
          Attaches the given object to this connection
 void setAutoflush(boolean autoflush)
          set autoflush.
 void setConnectionTimeoutSec(int timeoutSec)
          sets the max time for a connections.
 void setDefaultEncoding(java.lang.String encoding)
          sets the default encoding for this connection (used by string related methods like readString...)
 void setIdleTimeoutSec(int timeoutInSec)
          sets the idle timeout in sec
 IConnection setOption(java.lang.String name, java.lang.Object value)
          sets the value of a option
 void suspendRead()
          suspend reading data from the underlying subsystem
 int write(byte... bytes)
          sends bytes to the remote endpoint
 int write(byte b)
          sends a byte to the remote endpoint
 int write(byte[] bytes, int offset, int length)
          sends bytes to the remote endpoint
 int write(java.nio.ByteBuffer buffer)
          sends a byte buffer to the remote endpoint.
 long write(java.nio.ByteBuffer[] buffers)
          sends an array of byte buffer to the remote endpoint.
 int write(double d)
          sends a double to the remote endpoint
 int write(int i)
          sends an int to the remote endpoint
 int write(long l)
          sends a long to the remote endpoint
 int write(java.lang.String message)
          sends a message to the remote endpoint by using the connection default encoding
 int write(java.lang.String message, java.lang.String encoding)
          sends a message to the remote endpoint
 
Methods inherited from interface org.xsocket.IDataSource
readShort
 
Methods inherited from interface org.xsocket.IDataSink
write
 
Methods inherited from interface java.nio.channels.GatheringByteChannel
write
 
Methods inherited from interface java.nio.channels.Channel
close
 
Methods inherited from interface java.nio.channels.ReadableByteChannel
read
 

Field Detail

INITIAL_DEFAULT_ENCODING

static final java.lang.String INITIAL_DEFAULT_ENCODING
See Also:
Constant Field Values

INITIAL_AUTOFLUSH

static final boolean INITIAL_AUTOFLUSH
See Also:
Constant Field Values

SO_SNDBUF

static final java.lang.String SO_SNDBUF
See Also:
Constant Field Values

SO_RCVBUF

static final java.lang.String SO_RCVBUF
See Also:
Constant Field Values

SO_REUSEADDR

static final java.lang.String SO_REUSEADDR
See Also:
Constant Field Values

SO_KEEPALIVE

static final java.lang.String SO_KEEPALIVE
See Also:
Constant Field Values

SO_LINGER

static final java.lang.String SO_LINGER
See Also:
Constant Field Values

TCP_NODELAY

static final java.lang.String TCP_NODELAY
See Also:
Constant Field Values
Method Detail

getId

java.lang.String getId()
returns the id

Returns:
id

isOpen

boolean isOpen()
returns, if the connection is open.

Please note, that a connection could be closed, but reading of already received (and internally buffered) data wouldn`t fail. See also IDataHandler.onData(INonBlockingConnection)

Specified by:
isOpen in interface java.nio.channels.Channel
Returns:
true if the connection is open

flush

void flush()
           throws ClosedConnectionException,
                  java.io.IOException
flush the send buffer.

Specified by:
flush in interface java.io.Flushable
Throws:
java.io.IOException - If some other I/O error occurs
ClosedConnectionException - if the underlying channel is closed

getLocalPort

int getLocalPort()
returns the local port

Returns:
the local port

getLocalAddress

java.net.InetAddress getLocalAddress()
returns the local address

Returns:
the local IP address or InetAddress.anyLocalAddress() if the socket is not bound yet.

getRemoteAddress

java.net.InetAddress getRemoteAddress()
returns the remote address

Returns:
the remote address

getRemotePort

int getRemotePort()
returns the port of the remote endpoint

Returns:
the remote port

setDefaultEncoding

void setDefaultEncoding(java.lang.String encoding)
sets the default encoding for this connection (used by string related methods like readString...)

Parameters:
encoding - the default encoding

suspendRead

void suspendRead()
                 throws java.io.IOException
suspend reading data from the underlying subsystem

Throws:
java.io.IOException - If some other I/O error occurs

resumeRead

void resumeRead()
                throws java.io.IOException
resume reading data from the underlying subsystem

Throws:
java.io.IOException - If some other I/O error occurs

getDefaultEncoding

java.lang.String getDefaultEncoding()
gets the default encoding for this connection (used by string related methods like readString...)

Returns:
the default encoding

setAutoflush

void setAutoflush(boolean autoflush)
set autoflush. If autoflush is activated, each write call will cause a flush.

By default the autoflush is deactivated

Parameters:
autoflush - true if autoflush should be activated

getAutoflush

boolean getAutoflush()
get autoflush

Returns:
true, if autoflush is activated

getIdleTimeoutSec

int getIdleTimeoutSec()
returns the idle timeout in sec.

Returns:
idle timeout in sec

setIdleTimeoutSec

void setIdleTimeoutSec(int timeoutInSec)
sets the idle timeout in sec

Parameters:
timeoutInSec - idle timeout in sec

getConnectionTimeoutSec

int getConnectionTimeoutSec()
gets the connection timeout

Returns:
connection timeout

setConnectionTimeoutSec

void setConnectionTimeoutSec(int timeoutSec)
sets the max time for a connections. By exceeding this time the connection will be terminated

Parameters:
timeoutSec - the connection timeout in sec

getPendingWriteDataSize

int getPendingWriteDataSize()
returns the size of the data which have already been written, but not yet transferred to the underlying socket.

Returns:
the size of the pending data to write

activateSecuredMode

void activateSecuredMode()
                         throws java.io.IOException
ad hoc activation of a secured mode (SSL). By perfoming of this method all remaining data to send will be flushed. After this all data will be sent and received in the secured mode

Throws:
java.io.IOException - If some other I/O error occurs

write

int write(java.lang.String message,
          java.lang.String encoding)
          throws ClosedConnectionException,
                 java.io.IOException
sends a message to the remote endpoint

Specified by:
write in interface IDataSink
Parameters:
message - the message to send
encoding - the encoding which should be used th encode the chars into byte (e.g. `US-ASCII` or `UTF-8`)
Returns:
the number of send bytes
Throws:
java.io.IOException - If some other I/O error occurs
ClosedConnectionException - if the underlying channel is closed

write

int write(java.lang.String message)
          throws ClosedConnectionException,
                 java.io.IOException
sends a message to the remote endpoint by using the connection default encoding

Specified by:
write in interface IDataSink
Parameters:
message - the message to send
Returns:
the number of send bytes
Throws:
java.io.IOException - If some other I/O error occurs
ClosedConnectionException - if the underlying channel is closed

write

int write(byte b)
          throws ClosedConnectionException,
                 java.io.IOException
sends a byte to the remote endpoint

Specified by:
write in interface IDataSink
Parameters:
b - the byte to send
Returns:
the number of send bytes
Throws:
java.io.IOException - If some other I/O error occurs
ClosedConnectionException - if the underlying channel is closed

write

int write(byte... bytes)
          throws ClosedConnectionException,
                 java.io.IOException
sends bytes to the remote endpoint

Specified by:
write in interface IDataSink
Parameters:
bytes - the bytes to send
Returns:
the number of send bytes
Throws:
java.io.IOException - If some other I/O error occurs
ClosedConnectionException - if the underlying channel is closed

write

int write(byte[] bytes,
          int offset,
          int length)
          throws ClosedConnectionException,
                 java.io.IOException
sends bytes to the remote endpoint

Specified by:
write in interface IDataSink
Parameters:
bytes - the bytes to send
offset - The offset of the subarray to be used; must be non-negative and no larger than array.length. The new buffer`s position will be set to this value.
length - The length of the subarray to be used; must be non-negative and no larger than array.length - offset. The new buffer`s limit will be set to offset + length.
Returns:
the number of send bytes
Throws:
java.io.IOException - If some other I/O error occurs
ClosedConnectionException - if the underlying channel is closed

write

int write(java.nio.ByteBuffer buffer)
          throws ClosedConnectionException,
                 java.io.IOException
sends a byte buffer to the remote endpoint. In case of activated autoflush (for default see INITIAL_AUTOFLUSH) the behaviour is according to the WritableByteChannel specification. In case of user managed flushing (autoflush is off) the passed over buffers will only be queued internally and written after flushing the connection.

Specified by:
write in interface IDataSink
Specified by:
write in interface java.nio.channels.WritableByteChannel
Parameters:
buffer - the bytes to send
Returns:
the number of send bytes
Throws:
java.io.IOException - If some other I/O error occurs
ClosedConnectionException - if the underlying channel is closed

write

long write(java.nio.ByteBuffer[] buffers)
           throws ClosedConnectionException,
                  java.io.IOException
sends an array of byte buffer to the remote endpoint. In case of activated autoflush (for default see INITIAL_AUTOFLUSH) the behaviour is according to the WritableByteChannel specification. In case of user managed flushing (autoflush is off) the passed over buffers will only be queued internally and written after flushing the connection.

Specified by:
write in interface java.nio.channels.GatheringByteChannel
Specified by:
write in interface IDataSink
Parameters:
buffers - the bytes to send
Returns:
the number of send bytes
Throws:
java.io.IOException - If some other I/O error occurs
ClosedConnectionException - if the underlying channel is closed

write

int write(int i)
          throws ClosedConnectionException,
                 java.io.IOException
sends an int to the remote endpoint

Specified by:
write in interface IDataSink
Parameters:
i - the int value to send
Returns:
the number of send bytes
Throws:
java.io.IOException - If some other I/O error occurs
ClosedConnectionException - if the underlying channel is closed

write

int write(long l)
          throws ClosedConnectionException,
                 java.io.IOException
sends a long to the remote endpoint

Specified by:
write in interface IDataSink
Parameters:
l - the int value to send
Returns:
the number of send bytes
Throws:
java.io.IOException - If some other I/O error occurs
ClosedConnectionException - if the underlying channel is closed

write

int write(double d)
          throws ClosedConnectionException,
                 java.io.IOException
sends a double to the remote endpoint

Specified by:
write in interface IDataSink
Parameters:
d - the int value to send
Returns:
the number of send bytes
Throws:
java.io.IOException - If some other I/O error occurs
ClosedConnectionException - if the underlying channel is closed

readByte

byte readByte()
              throws java.io.IOException,
                     ClosedConnectionException
read a byte

Specified by:
readByte in interface IDataSource
Returns:
the byte value
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs

readInt

int readInt()
            throws java.io.IOException,
                   ClosedConnectionException
read an int

Specified by:
readInt in interface IDataSource
Returns:
the int value
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs

readLong

long readLong()
              throws java.io.IOException,
                     ClosedConnectionException
read a long

Specified by:
readLong in interface IDataSource
Returns:
the long value
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs

readDouble

double readDouble()
                  throws java.io.IOException,
                         ClosedConnectionException
read a double

Specified by:
readDouble in interface IDataSource
Returns:
the double value
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs

readByteBufferByDelimiter

java.nio.ByteBuffer[] readByteBufferByDelimiter(java.lang.String delimiter)
                                                throws java.io.IOException,
                                                       ClosedConnectionException
read a ByteBuffer by using a delimiter. The default encoing will be used to decode the delimiter To avoid memory leaks the readByteBufferByDelimiter(String, int) method is generally preferable
For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes

Parameters:
delimiter - the delimiter
Returns:
the ByteBuffer
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs

readByteBufferByDelimiter

java.nio.ByteBuffer[] readByteBufferByDelimiter(java.lang.String delimiter,
                                                int maxLength)
                                                throws java.io.IOException,
                                                       ClosedConnectionException,
                                                       MaxReadSizeExceededException
read a ByteBuffer by using a delimiter. The default encoing will be used to decode the delimiter For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes

Parameters:
delimiter - the delimiter
maxLength - the max length of bytes that should be read. If the limit is exceeded a MaxReadSizeExceededException will been thrown
Returns:
the ByteBuffer
Throws:
MaxReadSizeExceededException - If the max read length has been exceeded and the delimiter hasn’t been found
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs

readByteBufferByDelimiter

java.nio.ByteBuffer[] readByteBufferByDelimiter(java.lang.String delimiter,
                                                java.lang.String encoding,
                                                int maxLength)
                                                throws java.io.IOException,
                                                       ClosedConnectionException,
                                                       MaxReadSizeExceededException
read a ByteBuffer by using a delimiter For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes

Parameters:
delimiter - the delimiter
encoding - the encoding of the delimiter
maxLength - the max length of bytes that should be read. If the limit is exceeded a MaxReadSizeExceededException will been thrown
Returns:
the ByteBuffer
Throws:
MaxReadSizeExceededException - If the max read length has been exceeded and the delimiter hasn’t been found
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs

readByteBufferByLength

java.nio.ByteBuffer[] readByteBufferByLength(int length)
                                             throws java.io.IOException,
                                                    ClosedConnectionException
read a ByteBuffer by using a length defintion For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes

Parameters:
length - the amount of bytes to read
Returns:
the ByteBuffer
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs

readBytesByDelimiter

byte[] readBytesByDelimiter(java.lang.String delimiter)
                            throws java.io.IOException,
                                   ClosedConnectionException
read a byte array by using a delimiter. readByteBufferByDelimiter(String, int) To avoid memory leaks the readBytesByDelimiter(String, int) method is generally preferable
For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes

Parameters:
delimiter - the delimiter
Returns:
the read bytes
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs

readBytesByDelimiter

byte[] readBytesByDelimiter(java.lang.String delimiter,
                            int maxLength)
                            throws java.io.IOException,
                                   ClosedConnectionException,
                                   MaxReadSizeExceededException
read a byte array by using a delimiter. readByteBufferByDelimiter(String, int) For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes

Specified by:
readBytesByDelimiter in interface IDataSource
Parameters:
delimiter - the delimiter
maxLength - the max length of bytes that should be read. If the limit is exceeded a MaxReadSizeExceededException will been thrown
Returns:
the read bytes
Throws:
MaxReadSizeExceededException - If the max read length has been exceeded and the delimiter hasn’t been found
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs

readBytesByDelimiter

byte[] readBytesByDelimiter(java.lang.String delimiter,
                            java.lang.String encoding,
                            int maxLength)
                            throws java.io.IOException,
                                   ClosedConnectionException,
                                   MaxReadSizeExceededException
read a byte array by using a delimiter For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes

Parameters:
delimiter - the delimiter
encoding - the encoding of the delimiter
maxLength - the max length of bytes that should be read. If the limit is exceeded a MaxReadSizeExceededException will been thrown
Returns:
the read bytes
Throws:
MaxReadSizeExceededException - If the max read length has been exceeded and the delimiter hasn’t been found
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs

readBytesByLength

byte[] readBytesByLength(int length)
                         throws java.io.IOException,
                                ClosedConnectionException
read bytes by using a length defintion For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes

Specified by:
readBytesByLength in interface IDataSource
Parameters:
length - the amount of bytes to read
Returns:
the read bytes
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs

readStringByDelimiter

java.lang.String readStringByDelimiter(java.lang.String delimiter)
                                       throws java.io.IOException,
                                              ClosedConnectionException,
                                              java.io.UnsupportedEncodingException
read a string by using a delimiter and the connection default encoding To avoid memory leaks the readStringByDelimiter(String, int) method is generally preferable

Specified by:
readStringByDelimiter in interface IDataSource
Parameters:
delimiter - the delimiter
Returns:
the string
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs
java.io.UnsupportedEncodingException - if the default encoding is not supported

readStringByDelimiter

java.lang.String readStringByDelimiter(java.lang.String delimiter,
                                       int maxLength)
                                       throws java.io.IOException,
                                              ClosedConnectionException,
                                              java.io.UnsupportedEncodingException,
                                              MaxReadSizeExceededException
read a string by using a delimiter and the connection default encoding

Specified by:
readStringByDelimiter in interface IDataSource
Parameters:
delimiter - the delimiter
maxLength - the max length of bytes that should be read. If the limit is exceeded a MaxReadSizeExceededException will been thrown
Returns:
the string
Throws:
MaxReadSizeExceededException - If the max read length has been exceeded and the delimiter hasn’t been found
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs
java.io.UnsupportedEncodingException - if the default encoding is not supported

readStringByLength

java.lang.String readStringByLength(int length)
                                    throws java.io.IOException,
                                           ClosedConnectionException,
                                           java.io.UnsupportedEncodingException
read a string by using a length definition and the connection default encoding

Specified by:
readStringByLength in interface IDataSource
Parameters:
length - the amount of bytes to read
Returns:
the string
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs
java.io.UnsupportedEncodingException - if the given encoding is not supported

readStringByDelimiter

java.lang.String readStringByDelimiter(java.lang.String delimiter,
                                       java.lang.String encoding)
                                       throws java.io.IOException,
                                              ClosedConnectionException,
                                              java.io.UnsupportedEncodingException
read a string by using a delimiter To avoid memory leaks the readStringByDelimiter(String, String, int) method is generally preferable

Parameters:
delimiter - the delimiter
encoding - the encodin to use
Returns:
the string
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs
java.io.UnsupportedEncodingException - If the given encoding is not supported

readStringByDelimiter

java.lang.String readStringByDelimiter(java.lang.String delimiter,
                                       java.lang.String encoding,
                                       int maxLength)
                                       throws java.io.IOException,
                                              ClosedConnectionException,
                                              java.io.UnsupportedEncodingException,
                                              MaxReadSizeExceededException
read a string by using a delimiter

Specified by:
readStringByDelimiter in interface IDataSource
Parameters:
delimiter - the delimiter
encoding - the encodin to use
maxLength - the max length of bytes that should be read. If the limit is exceeded a MaxReadSizeExceededException will been thrown
Returns:
the string
Throws:
MaxReadSizeExceededException - If the max read length has been exceeded and the delimiter hasn’t been found
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs
java.io.UnsupportedEncodingException - If the given encoding is not supported

readStringByLength

java.lang.String readStringByLength(int length,
                                    java.lang.String encoding)
                                    throws java.io.IOException,
                                           ClosedConnectionException,
                                           java.io.UnsupportedEncodingException
read a string by using a length definition

Specified by:
readStringByLength in interface IDataSource
Parameters:
length - the amount of bytes to read
encoding - the encodin to use
Returns:
the string
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs
java.io.UnsupportedEncodingException - if the given encoding is not supported

getIndexOf

int getIndexOf(java.lang.String str)
               throws java.io.IOException,
                      ClosedConnectionException
Returns the index of the first occurrence of the given string. The default encoing will be used to decode the string

Parameters:
str - any string
Returns:
if the string argument occurs as a substring within this object, then the index of the first character of the first such substring is returned;
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs

getIndexOf

int getIndexOf(java.lang.String str,
               int maxLength)
               throws java.io.IOException,
                      ClosedConnectionException,
                      MaxReadSizeExceededException
Returns the index of the first occurrence of the given string. The default encoing will be used to decode the string

Parameters:
str - any string
maxLength - the max length of bytes that should be read. If the limit is exceeded a MaxReadSizeExceededException will been thrown
Returns:
if the string argument occurs as a substring within this object, then the index of the first character of the first such substring is returned;
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs
MaxReadSizeExceededException - If the max read length has been exceeded and the delimiter hasn’t been found

getIndexOf

int getIndexOf(java.lang.String str,
               java.lang.String encoding,
               int maxLength)
               throws java.io.IOException,
                      ClosedConnectionException,
                      MaxReadSizeExceededException
Returns the index of the first occurrence of the given string.

Parameters:
str - any string
encoding - the encoding of the string
maxLength - the max length of bytes that should be read. If the limit is exceeded a MaxReadSizeExceededException will been thrown
Returns:
if the string argument occurs as a substring within this object, then the index of the first character of the first such substring is returned;
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs
MaxReadSizeExceededException - If the max read length has been exceeded and the delimiter hasn’t been found

markWritePosition

void markWritePosition()
Marks the present write position in the connection. Subsequent calls to resetToReadMark() will attempt to reposition the connection to this point. The write read become in valid by flushing the connection.

write mark is only supported for autoflush off. E.g.
 ...
 con.setAutoflush(false);

 con.markWritePosition();  // mark current position
 con.write((int) 0);       // write "emtpy" length field

 int written = con.write("hello world");
 written += con.write(" it’s nice to be here");
 ...

 con.resetToWriteMark();  // return to length field position
 con.write(written);      // and update it

 con.flush(); // flush (marker will be removed implicit)
…    * 


removeWriteMark

void removeWriteMark()
remove the mark the present write position in the connection.


resetToWriteMark

boolean resetToWriteMark()
Resets to the marked write position. If the connection has been marked, then attempt to reposition it at the mark.

Returns:
true, if reset was successful

markReadPosition

void markReadPosition()
Marks the present read position in the connection. Subsequent calls to resetToReadMark() will attempt to reposition the connection to this point.


removeReadMark

void removeReadMark()
remove the mark the present read position in the connection.


resetToReadMark

boolean resetToReadMark()
Resets to the marked read position. If the connection has been marked, then attempt to reposition it at the mark.

Returns:
true, if reset was successful

setAttachment

void setAttachment(java.lang.Object obj)
Attaches the given object to this connection

Parameters:
obj - The object to be attached; may be null

getAttachment

java.lang.Object getAttachment()
Retrieves the current attachment.

Returns:
The object currently attached to this key, or null if there is no attachment

attach

java.lang.Object attach(java.lang.Object obj)
Deprecated. use setAttachment(Object) instead


attachment

java.lang.Object attachment()
Deprecated. use getAttachment() instead


setOption

IConnection setOption(java.lang.String name,
                      java.lang.Object value)
                      throws java.io.IOException
sets the value of a option

Parameters:
name - the name of the option
value - the value of the option
Returns:
the IConnection
Throws:
java.io.IOException - In an I/O error occurs

getOption

java.lang.Object getOption(java.lang.String name)
                           throws java.io.IOException
returns the value of a option

Parameters:
name - the name of the option
Returns:
the value of the option
Throws:
java.io.IOException - In an I/O error occurs

getOptions

java.util.Map<java.lang.String,java.lang.Class> getOptions()
Returns an unmodifiable map of the options supported by this endpoint. The key in the returned map is the name of a option, and its value is the type of the option value. The returned map will never contain null keys or values.

Returns:
An unmodifiable map of the options supported by this channel