org.xsocket.stream
Interface INonBlockingConnection

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

public interface INonBlockingConnection
extends IConnection

A connection which uses the underlying channel in a non-blocking manner.


Nested Class Summary
static class INonBlockingConnection.TransferResult
           
 
Nested classes/interfaces inherited from interface org.xsocket.stream.IConnection
IConnection.FlushMode
 
Field Summary
static IConnection.FlushMode INITIAL_FLUSH_MODE
           
static int UNLIMITED
           
 
Fields inherited from interface org.xsocket.stream.IConnection
INITIAL_AUTOFLUSH, INITIAL_DEFAULT_ENCODING, SO_KEEPALIVE, SO_LINGER, SO_RCVBUF, SO_REUSEADDR, SO_SNDBUF, TCP_NODELAY
 
Method Summary
 void flush()
          flush the send buffer.
 IConnection.FlushMode getFlushmode()
          return the flushmode
 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 getNumberOfAvailableBytes()
          get the number of available bytes to read
 int indexOf(java.lang.String str)
          Deprecated. uses getIndexOf instead
 java.nio.ByteBuffer[] readAvailable()
          read all received bytes
 boolean readAvailableByDelimiter(java.lang.String delimiter, java.lang.String encoding, java.nio.channels.WritableByteChannel outputChannel)
          Deprecated. use transferToAvailableByDelimiter(String, String, WritableByteChannel) instead
 boolean readAvailableByDelimiter(java.lang.String delimiter, java.nio.channels.WritableByteChannel outputChannel)
          Deprecated. use transferToAvailableByDelimiter(String, WritableByteChannel) instead
 byte readByte()
          read a byte
 java.nio.ByteBuffer[] readByteBufferByDelimiter(java.lang.String delimiter)
          read a ByteBuffer by using a 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
 java.nio.ByteBuffer[] readByteBufferByDelimiter(java.lang.String delimiter, 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 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 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 setFlushmode(IConnection.FlushMode flushMode)
          set the flush mode

By setting the flushmode with ASYNC (default is SYNC) the data will be transferred to the underlying connection in a asynchronous way.
 INonBlockingConnection setOption(java.lang.String name, java.lang.Object value)
          sets the value of a option
 void setWriteTransferRate(int bytesPerSecond)
          set the send delay time.
 INonBlockingConnection.TransferResult transferToAvailableByDelimiter(java.lang.String delimiter, java.lang.String encoding, java.nio.channels.WritableByteChannel outputChannel)
          transfers bytes from this connection to the given writable byte channel.
 INonBlockingConnection.TransferResult transferToAvailableByDelimiter(java.lang.String delimiter, java.nio.channels.WritableByteChannel outputChannel)
          transfers bytes from this connection to the given writable byte channel.
 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.
 
Methods inherited from interface org.xsocket.stream.IConnection
activateSecuredMode, attach, attachment, getAttachment, getAutoflush, getConnectionTimeoutSec, getDefaultEncoding, getId, getIdleTimeoutSec, getIndexOf, getLocalAddress, getLocalPort, getOption, getOptions, getPendingWriteDataSize, getRemoteAddress, getRemotePort, isOpen, markReadPosition, markWritePosition, readByteBufferByDelimiter, readBytesByDelimiter, removeReadMark, removeWriteMark, resetToReadMark, resetToWriteMark, resumeRead, setAttachment, setAutoflush, setConnectionTimeoutSec, setDefaultEncoding, setIdleTimeoutSec, suspendRead, write, write, write, write, write, write, write, write
 
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

UNLIMITED

static final int UNLIMITED
See Also:
Constant Field Values

INITIAL_FLUSH_MODE

static final IConnection.FlushMode INITIAL_FLUSH_MODE
Method Detail

getNumberOfAvailableBytes

int getNumberOfAvailableBytes()
get the number of available bytes to read

Returns:
the umber of available bytes

indexOf

int indexOf(java.lang.String str)
Deprecated. uses getIndexOf instead

Returns the index of the first occurrence of the given 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; if it does not occur as a substring, -1 is returned.

getIndexOf

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

Specified by:
getIndexOf in interface IConnection
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
java.nio.BufferUnderflowException - if the given string has not been found

getIndexOf

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

Specified by:
getIndexOf in interface IConnection
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
java.nio.BufferUnderflowException - if the given string has not been found

readAvailable

java.nio.ByteBuffer[] readAvailable()
                                    throws java.io.IOException,
                                           ClosedConnectionException
read all received bytes

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

readAvailableByDelimiter

boolean readAvailableByDelimiter(java.lang.String delimiter,
                                 java.nio.channels.WritableByteChannel outputChannel)
                                 throws java.io.IOException,
                                        ClosedConnectionException
Deprecated. use transferToAvailableByDelimiter(String, WritableByteChannel) instead

Throws:
java.io.IOException
ClosedConnectionException

readAvailableByDelimiter

boolean readAvailableByDelimiter(java.lang.String delimiter,
                                 java.lang.String encoding,
                                 java.nio.channels.WritableByteChannel outputChannel)
                                 throws java.io.IOException,
                                        ClosedConnectionException
Deprecated. use transferToAvailableByDelimiter(String, String, WritableByteChannel) instead

Throws:
java.io.IOException
ClosedConnectionException

transferToAvailableByDelimiter

INonBlockingConnection.TransferResult transferToAvailableByDelimiter(java.lang.String delimiter,
                                                                     java.nio.channels.WritableByteChannel outputChannel)
                                                                     throws ClosedConnectionException,
                                                                            java.io.IOException,
                                                                            java.net.SocketTimeoutException
transfers bytes from this connection to the given writable byte channel. All available bytes buffers terminated by the delimiter will be transfered. if the delimiter has been found the INonBlockingConnection.TransferResult.delimiterFound is set with true. The INonBlockingConnection.TransferResult.written contains the The number of bytes, possibly zero, that were actually transferred
The default encoding will be used to decode the delimiter

Parameters:
delimiter - the delimiter to use
outputChannel - the output channel to write the available bytes
Returns:
transfer result
Throws:
java.io.IOException - If some other I/O error occurs
java.net.SocketTimeoutException - If the receive timeout has been reached (will only been thrown if autoflush = true)
ClosedConnectionException - if the underlying channel is closed

transferToAvailableByDelimiter

INonBlockingConnection.TransferResult transferToAvailableByDelimiter(java.lang.String delimiter,
                                                                     java.lang.String encoding,
                                                                     java.nio.channels.WritableByteChannel outputChannel)
                                                                     throws ClosedConnectionException,
                                                                            java.io.IOException,
                                                                            java.net.SocketTimeoutException
transfers bytes from this connection to the given writable byte channel. All available bytes buffers terminated by the delimiter will be transfered. if the delimiter has been found the INonBlockingConnection.TransferResult.delimiterFound is set with true. The INonBlockingConnection.TransferResult.written contains the The number of bytes, possibly zero, that were actually transferred

Parameters:
delimiter - the delimiter to use
encoding - the encoding of the delimiter
outputChannel - the output channel to write the available bytes
Returns:
transfer the transfer result
Throws:
java.io.IOException - If some other I/O error occurs
java.net.SocketTimeoutException - If the receive timeout has been reached (will only been thrown if autoflush = true)
ClosedConnectionException - if the underlying channel is closed

readByteBufferByDelimiter

java.nio.ByteBuffer[] readByteBufferByDelimiter(java.lang.String delimiter)
                                                throws java.io.IOException,
                                                       ClosedConnectionException,
                                                       java.nio.BufferUnderflowException
read a ByteBuffer by using a 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

Specified by:
readByteBufferByDelimiter in interface IConnection
Parameters:
delimiter - the delimiter
Returns:
the ByteBuffer
Throws:
java.io.IOException - If some other I/O error occurs
java.nio.BufferUnderflowException - if the delimiter has not been found
ClosedConnectionException - If the underlying socket is already closed

readByteBufferByDelimiter

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

Specified by:
readByteBufferByDelimiter in interface IConnection
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 * @throws ClosedConnectionException If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs
java.nio.BufferUnderflowException - if the delimiter has not been found
ClosedConnectionException - If the underlying socket is already closed

readByteBufferByLength

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

Specified by:
readByteBufferByLength in interface IConnection
Parameters:
length - the amount of bytes to read
Returns:
the ByteBuffer
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.nio.BufferUnderflowException - if the buffer`s limit has been reached
java.io.IOException - If some other I/O error occurs

readBytesByDelimiter

byte[] readBytesByDelimiter(java.lang.String delimiter)
                            throws java.io.IOException,
                                   ClosedConnectionException,
                                   java.nio.BufferUnderflowException
read a byte array by using a delimiter 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

Specified by:
readBytesByDelimiter in interface IConnection
Parameters:
delimiter - the delimiter
Returns:
the read bytes
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.nio.BufferUnderflowException - if the delimiter has not been found
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,
                                   java.nio.BufferUnderflowException
read a byte array by using a delimiter For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes

Specified by:
readBytesByDelimiter in interface IConnection
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 * @throws ClosedConnectionException If the underlying socket is already closed
java.nio.BufferUnderflowException - if the delimiter has not been found
java.io.IOException - If some other I/O error occurs
ClosedConnectionException - If the underlying socket is already closed

readBytesByLength

byte[] readBytesByLength(int length)
                         throws java.io.IOException,
                                ClosedConnectionException,
                                java.nio.BufferUnderflowException
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 IConnection
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.nio.BufferUnderflowException - if the buffer`s limit has been reached
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.nio.BufferUnderflowException,
                                              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 IConnection
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.nio.BufferUnderflowException - if the delimiter has not been found
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.nio.BufferUnderflowException,
                                              java.io.UnsupportedEncodingException,
                                              MaxReadSizeExceededException
read a string by using a delimiter and the connection default encoding

Specified by:
readStringByDelimiter in interface IConnection
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.nio.BufferUnderflowException - if the delimiter has not been found
java.io.UnsupportedEncodingException - if the default encoding is not supported

readStringByLength

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

Specified by:
readStringByLength in interface IConnection
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.nio.BufferUnderflowException - if the buffer`s limit has been reached
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.nio.BufferUnderflowException,
                                              java.io.UnsupportedEncodingException
read a string by using a delimiter To avoid memory leaks the readStringByDelimiter(String, String, int) method is generally preferable

Specified by:
readStringByDelimiter in interface IConnection
Parameters:
delimiter - the delimiter
encoding - the encodin to use
Returns:
the string
Throws:
java.io.IOException - If some other I/O error occurs
java.nio.BufferUnderflowException - if the buffer`s limit has been reached
java.io.UnsupportedEncodingException - If the given encoding is not supported
ClosedConnectionException - If the underlying socket is already closed

readStringByDelimiter

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

Specified by:
readStringByDelimiter in interface IConnection
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 * @throws ClosedConnectionException If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs
java.nio.BufferUnderflowException - if the buffer`s limit has been reached
java.io.UnsupportedEncodingException - If the given encoding is not supported
ClosedConnectionException - If the underlying socket is already closed

readStringByLength

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

Specified by:
readStringByLength in interface IConnection
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.nio.BufferUnderflowException - if the buffer`s limit has been reached
java.io.IOException - If some other I/O error occurs
java.io.UnsupportedEncodingException - if the given encoding is not supported

readInt

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

Specified by:
readInt in interface IConnection
Specified by:
readInt in interface IDataSource
Returns:
the int value
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.nio.BufferUnderflowException - if the buffer`s limit has been reached
java.io.IOException - If some other I/O error occurs

readLong

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

Specified by:
readLong in interface IConnection
Specified by:
readLong in interface IDataSource
Returns:
the long value
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.nio.BufferUnderflowException - if the buffer`s limit has been reached
java.io.IOException - If some other I/O error occurs

readDouble

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

Specified by:
readDouble in interface IConnection
Specified by:
readDouble in interface IDataSource
Returns:
the double value
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.nio.BufferUnderflowException - if the buffer`s limit has been reached
java.io.IOException - If some other I/O error occurs

readByte

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

Specified by:
readByte in interface IConnection
Specified by:
readByte in interface IDataSource
Returns:
the byte value
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.nio.BufferUnderflowException - if the buffer`s limit has been reached
java.io.IOException - If some other I/O error occurs

setWriteTransferRate

void setWriteTransferRate(int bytesPerSecond)
                          throws ClosedConnectionException,
                                 java.io.IOException
set the send delay time. WData to write will be buffered internally and be written to the underlying subsystem based on the given write rate. The write methods will not block for this time.
By default the write transfer rate is set with UNLIMITED

Reduced write transfer is only supported for FlushMode.ASYNC. see setFlushmode(org.xsocket.stream.IConnection.FlushMode)

Parameters:
bytesPerSecond - the transfer rate of the outgoing data
Throws:
ClosedConnectionException - If the underlying socket is already closed
java.io.IOException - If some other I/O error occurs

flush

void flush()
           throws ClosedConnectionException,
                  java.io.IOException
flush the send buffer. The method call returns immediately. The outgoing data will be flushed into the underlying os-specific send buffer asynchronously in the background

Specified by:
flush in interface java.io.Flushable
Specified by:
flush in interface IConnection
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 IConnection.INITIAL_AUTOFLUSH) and flushmode SYNC (for default see INITIAL_FLUSH_MODE 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 IConnection
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
See Also:
IConnection.setAutoflush(boolean), setFlushmode(org.xsocket.stream.IConnection.FlushMode)

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 IConnection.INITIAL_AUTOFLUSH) and flushmode SYNC (for default see INITIAL_FLUSH_MODE 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 IConnection
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
See Also:
IConnection.setAutoflush(boolean), setFlushmode(org.xsocket.stream.IConnection.FlushMode)

setFlushmode

void setFlushmode(IConnection.FlushMode flushMode)
set the flush mode

By setting the flushmode with ASYNC (default is SYNC) the data will be transferred to the underlying connection in a asynchronous way. In most cases there are high performance improvements. If the IConnection.write(ByteBuffer) or IConnection.write(ByteBuffer[]) method will be used, the flushmode FlushMode#ASYNC could have side-effects. Because the buffer will be written asynchronous, it could occur, that the passed-over buffers are not already written by returning from the write call.

Parameters:
flushMode - FlushMode#ASYNC if flush should be performed asynchronous, FlushMode#SYNC if flush should be perform synchronous

getFlushmode

IConnection.FlushMode getFlushmode()
return the flushmode

Returns:
the flushmode

setOption

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

Specified by:
setOption in interface IConnection
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