| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||

java.lang.Objectorg.xsocket.connection.AbstractNonBlockingStream
public abstract class AbstractNonBlockingStream
implementation base of a data stream.   
 
 
This is a xSocket internal class and subject to change
| Constructor Summary | |
|---|---|
| AbstractNonBlockingStream() | |
| Method Summary | |
|---|---|
| protected  void | appendDataToReadBuffer(ByteBuffer[] data)Deprecated. | 
| protected  void | appendDataToReadBuffer(ByteBuffer[] data,
                       int size)append data to the read buffer | 
|  int | available()get the number of available bytes to read | 
|  void | close() | 
| protected  ByteBuffer[] | drainWriteQueue()drains the write buffer | 
|  Object | getAttachment()Retrieves the current attachment. | 
|  String | getEncoding()gets the default encoding | 
|  IConnection.FlushMode | getFlushmode()return the flush mode | 
|  int | getReadBufferVersion()get the version of read buffer. | 
| protected  int | getReadQueueSize()returns the read queue size without additional check | 
| protected  int | getWriteBufferSize()gets the write buffer size | 
| protected  int | getWriteTransferChunkeSize()returns the default chunk size for writing | 
|  int | indexOf(String str)Returns the index of the first occurrence of the given string. | 
|  int | indexOf(String str,
        String encoding)Returns the index of the first occurrence of the given string. | 
|  boolean | isAutoflush()get autoflush | 
| protected abstract  boolean | isDataWriteable()returns true, if the underlying data sink is open | 
| protected abstract  boolean | isMoreInputDataExpected()returns true, if the underlying data source is open | 
| protected  boolean | isReadBufferEmpty()returns if the read buffer is empty | 
| protected  boolean | isWriteBufferEmpty()returns if the write buffer is empty | 
|  void | markReadPosition()Marks the read position in the connection. | 
|  void | markWritePosition()Marks the write position in the connection. | 
| protected  void | onPostAppend() | 
| protected  void | onPostRead()notification method which will be called after data has been read | 
| protected  void | onPreWrite(int size)call back method which will be called before writing data into the write queue | 
| protected  void | onWriteDataInserted()notification, that data has been inserted | 
| protected  String | printReadBuffer(String encoding)prints the read buffer content | 
| protected  String | printWriteBuffer(String encoding)prints the write buffer content | 
|  int | read(ByteBuffer buffer)see ReadableByteChannel.read(ByteBuffer) | 
|  byte | readByte()read a byte | 
|  ByteBuffer[] | readByteBufferByDelimiter(String delimiter)read a ByteBuffer by using a delimiter. | 
|  ByteBuffer[] | readByteBufferByDelimiter(String delimiter,
                          int maxLength)read a ByteBuffer by using a delimiter For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes | 
|  ByteBuffer[] | readByteBufferByDelimiter(String delimiter,
                          String encoding)read a ByteBuffer by using a delimiter For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes | 
|  ByteBuffer[] | readByteBufferByDelimiter(String delimiter,
                          String encoding,
                          int maxLength)read a ByteBuffer by using a delimiter For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes | 
|  ByteBuffer[] | readByteBufferByLength(int length)read a ByteBuffer | 
|  byte[] | readBytesByDelimiter(String delimiter)read a byte array by using a delimiter For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes | 
|  byte[] | readBytesByDelimiter(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[] | readBytesByDelimiter(String delimiter,
                     String encoding)read a byte array by using a delimiter For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes | 
|  byte[] | readBytesByDelimiter(String delimiter,
                     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 definition | 
|  double | readDouble()read a double | 
|  int | readInt()read an int | 
|  long | readLong()read a long | 
|  short | readShort()read a short value | 
| protected  ByteBuffer | readSingleByteBuffer(int length)read a byte buffer by length. | 
|  String | readStringByDelimiter(String delimiter)read a string by using a delimiter | 
|  String | readStringByDelimiter(String delimiter,
                      int maxLength)read a string by using a delimiter | 
|  String | readStringByDelimiter(String delimiter,
                      String encoding)read a string by using a delimiter | 
|  String | readStringByDelimiter(String delimiter,
                      String encoding,
                      int maxLength)read a string by using a delimiter | 
|  String | readStringByLength(int length)read a string by using a length definition | 
|  String | readStringByLength(int length,
                   String encoding)read a string by using a length definition | 
|  void | removeReadMark()remove the read mark | 
|  void | removeWriteMark()remove the write mark | 
| protected  boolean | reset()resets the stream | 
|  boolean | resetToReadMark()Resets to the marked read position. | 
|  boolean | resetToWriteMark()Resets to the marked write position. | 
|  void | setAttachment(Object obj)Attaches the given object to this connection | 
|  void | setAutoflush(boolean autoflush)set autoflush. | 
|  void | setEncoding(String defaultEncoding)sets the default encoding | 
|  void | setFlushmode(IConnection.FlushMode flushMode)set the flush mode By setting the flush mode with ASYNC (default is SYNC) the data will be transferred to the underlying connection in a asynchronous way. | 
|  long | transferFrom(FileChannel fileChannel)transfer the data of the file channel to this data sink | 
|  long | transferFrom(ReadableByteChannel source)transfer the data of the source channel to this data sink | 
|  long | transferFrom(ReadableByteChannel source,
             int chunkSize)transfer the data of the source channel to this data sink | 
|  long | transferTo(WritableByteChannel target,
           int length)transfer the data of the this source channel to the given data sink | 
|  int | write(byte... bytes)writes bytes to the data sink | 
|  int | write(byte b)writes a byte to the data sink | 
|  int | write(byte[] bytes,
      int offset,
      int length)writes bytes to the data sink | 
|  int | write(ByteBuffer buffer)WritableByteChannel.write(ByteBuffer) | 
|  long | write(ByteBuffer[] buffers)see GatheringByteChannel.write(ByteBuffer[]) | 
|  long | write(ByteBuffer[] srcs,
      int offset,
      int length)see GatheringByteChannel.write(ByteBuffer[], int, int) | 
|  int | write(double d)writes a double to the data sink | 
|  int | write(int i)writes a int to the data sink | 
|  long | write(List<ByteBuffer> buffers)writes a list of bytes to the data sink | 
|  int | write(long l)writes a long to the data sink | 
|  int | write(short s)writes a short to the data sink | 
|  int | write(String message)writes a message | 
|  int | write(String message,
      String encoding)writes a message | 
| Methods inherited from class java.lang.Object | 
|---|
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Methods inherited from interface java.nio.channels.Channel | 
|---|
| isOpen | 
| Constructor Detail | 
|---|
public AbstractNonBlockingStream()
| Method Detail | 
|---|
public void close()
           throws IOException
close in interface Closeableclose in interface ChannelIOExceptionpublic final void setAttachment(Object obj)
obj - The object to be attached; may be nullpublic final Object getAttachment()
public final void setEncoding(String defaultEncoding)
defaultEncoding - the default encodingpublic final String getEncoding()
public void setFlushmode(IConnection.FlushMode flushMode)
flushMode - IConnection.FlushMode.ASYNC if flush should be performed asynchronous,
                  IConnection.FlushMode.SYNC if flush should be perform synchronouspublic final IConnection.FlushMode getFlushmode()
protected int getWriteTransferChunkeSize()
public final void setAutoflush(boolean autoflush)
autoflush - true if autoflush should be activatedpublic final boolean isAutoflush()
protected abstract boolean isMoreInputDataExpected()
protected abstract boolean isDataWriteable()
public int indexOf(String str)
            throws IOException,
                   ClosedChannelException
str - any string
IOException - If some other I/O error occurs
ClosedChannelException - If the stream is closed
public int indexOf(String str,
                   String encoding)
            throws IOException,
                   ClosedChannelException
str - any stringencoding - the encoding to use
IOException - If some other I/O error occurs
ClosedChannelException - If the stream is closed
public int available()
              throws IOException
IOException - if an exception has been occurredprotected int getReadQueueSize()
public int getReadBufferVersion()
protected void onPostRead()
                   throws IOException
IOException - If some other I/O error occurs
public byte readByte()
              throws IOException,
                     BufferUnderflowException,
                     ClosedChannelException
IOException - If some other I/O error occurs
BufferUnderflowException - if not enough data is available
ClosedChannelException - If the stream is closed
public short readShort()
                throws IOException,
                       BufferUnderflowException,
                       ClosedChannelException
IOException - If some other I/O error occurs
BufferUnderflowException - if not enough data is available
ClosedChannelException - If the stream is closed
public int readInt()
            throws IOException,
                   BufferUnderflowException,
                   ClosedChannelException
IOException - If some other I/O error occurs
BufferUnderflowException - if not enough data is available
ClosedChannelException - If the stream is closed
public long readLong()
              throws IOException,
                     BufferUnderflowException,
                     ClosedChannelException
IOException - If some other I/O error occurs
BufferUnderflowException - if not enough data is available
ClosedChannelException - If the stream is closed
public double readDouble()
                  throws IOException,
                         BufferUnderflowException,
                         ClosedChannelException
IOException - If some other I/O error occurs
BufferUnderflowException - if not enough data is available
ClosedChannelException - If the stream is closed
public int read(ByteBuffer buffer)
         throws IOException,
                ClosedChannelException
ReadableByteChannel.read(ByteBuffer)
IOException
ClosedChannelException
public ByteBuffer[] readByteBufferByDelimiter(String delimiter)
                                       throws IOException,
                                              BufferUnderflowException,
                                              ClosedChannelException
IReadWriteableConnection#readByteBufferByDelimiter(String, int) method is generally preferable  
 
delimiter - the delimiter
IOException - If some other I/O error occurs
BufferUnderflowException - if not enough data is available
ClosedChannelException - If the stream is closed
public ByteBuffer[] readByteBufferByDelimiter(String delimiter,
                                              int maxLength)
                                       throws IOException,
                                              BufferUnderflowException,
                                              MaxReadSizeExceededException,
                                              ClosedChannelException
delimiter - the delimitermaxLength - the max length of bytes that should be read. If the limit is exceeded a MaxReadSizeExceededException will been thrown
MaxReadSizeExceededException - If the max read length has been exceeded and the delimiter hasn’t been found
IOException - If some other I/O error occurs
BufferUnderflowException - if not enough data is available
ClosedChannelException - If the stream is closed
public ByteBuffer[] readByteBufferByDelimiter(String delimiter,
                                              String encoding)
                                       throws IOException,
                                              BufferUnderflowException,
                                              ClosedChannelException
delimiter - the delimiterencoding - the delimiter encoding
MaxReadSizeExceededException - If the max read length has been exceeded and the delimiter hasn’t been found
IOException - If some other I/O error occurs
BufferUnderflowException - if not enough data is available
ClosedChannelException - If the stream is closed
public ByteBuffer[] readByteBufferByDelimiter(String delimiter,
                                              String encoding,
                                              int maxLength)
                                       throws IOException,
                                              BufferUnderflowException,
                                              MaxReadSizeExceededException,
                                              ClosedChannelException
delimiter - the delimiterencoding - the delimiter encodingmaxLength - the max length of bytes that should be read. If the limit is exceeded a MaxReadSizeExceededException will been thrown
MaxReadSizeExceededException - If the max read length has been exceeded and the delimiter hasn’t been found
IOException - If some other I/O error occurs
BufferUnderflowException - if not enough data is available
ClosedChannelException - If the stream is closed
public ByteBuffer[] readByteBufferByLength(int length)
                                    throws IOException,
                                           BufferUnderflowException,
                                           ClosedChannelException
length - the length could be negative, in this case a empty array will be returned
IOException - If some other I/O error occurs
BufferUnderflowException - if not enough data is available
ClosedChannelException - If the stream is closed
public byte[] readBytesByDelimiter(String delimiter)
                            throws IOException,
                                   BufferUnderflowException,
                                   ClosedChannelException
delimiter - the delimiter
IOException - If some other I/O error occurs
BufferUnderflowException - if not enough data is available
ClosedChannelException - If the stream is closed
public byte[] readBytesByDelimiter(String delimiter,
                                   int maxLength)
                            throws IOException,
                                   BufferUnderflowException,
                                   MaxReadSizeExceededException,
                                   ClosedChannelException
delimiter - the delimitermaxLength - the max length of bytes that should be read. If the limit is exceeded a MaxReadSizeExceededException will been thrown
MaxReadSizeExceededException - If the max read length has been exceeded and the delimiter hasn’t been found
IOException - If some other I/O error occurs
BufferUnderflowException - if not enough data is available
ClosedChannelException - If the stream is closed
public byte[] readBytesByDelimiter(String delimiter,
                                   String encoding)
                            throws IOException,
                                   BufferUnderflowException,
                                   ClosedChannelException
delimiter - the delimiterencoding - the delimiter encoding
MaxReadSizeExceededException - If the max read length has been exceeded and the delimiter hasn’t been found
IOException - If some other I/O error occurs
BufferUnderflowException - if not enough data is available
ClosedChannelException - If the stream is closed
public byte[] readBytesByDelimiter(String delimiter,
                                   String encoding,
                                   int maxLength)
                            throws IOException,
                                   BufferUnderflowException,
                                   MaxReadSizeExceededException,
                                   ClosedChannelException
delimiter - the delimiterencoding - the delimiter encodingmaxLength - the max length of bytes that should be read. If the limit is exceeded a MaxReadSizeExceededException will been thrown
MaxReadSizeExceededException - If the max read length has been exceeded and the delimiter hasn’t been found
IOException - If some other I/O error occurs
BufferUnderflowException - if not enough data is available
ClosedChannelException - If the stream is closed
public byte[] readBytesByLength(int length)
                         throws IOException,
                                BufferUnderflowException,
                                ClosedChannelException
length - the amount of bytes to read
IOException - If some other I/O error occurs
IllegalArgumentException, - if the length parameter is negative
BufferUnderflowException - if not enough data is available
ClosedChannelException - If the stream is closed
public String readStringByDelimiter(String delimiter)
                             throws IOException,
                                    BufferUnderflowException,
                                    UnsupportedEncodingException,
                                    ClosedChannelException
delimiter - the delimiter
IOException - If some other I/O error occurs
UnsupportedEncodingException - if the default encoding is not supported
BufferUnderflowException - if not enough data is available
ClosedChannelException - If the stream is closed
public String readStringByDelimiter(String delimiter,
                                    int maxLength)
                             throws IOException,
                                    BufferUnderflowException,
                                    UnsupportedEncodingException,
                                    MaxReadSizeExceededException,
                                    ClosedChannelException
delimiter - the delimitermaxLength - the max length of bytes that should be read. If the limit is exceeded a MaxReadSizeExceededException will been thrown
MaxReadSizeExceededException - If the max read length has been exceeded and the delimiter hasn’t been found
IOException - If some other I/O error occurs
UnsupportedEncodingException - If the given encoding is not supported
BufferUnderflowException - if not enough data is available
ClosedChannelException - If the stream is closed
public String readStringByDelimiter(String delimiter,
                                    String encoding)
                             throws IOException,
                                    BufferUnderflowException,
                                    UnsupportedEncodingException,
                                    MaxReadSizeExceededException,
                                    ClosedChannelException
delimiter - the delimiterencoding - the encoding
MaxReadSizeExceededException - If the max read length has been exceeded and the delimiter hasn’t been found
IOException - If some other I/O error occurs
UnsupportedEncodingException - If the given encoding is not supported
BufferUnderflowException - if not enough data is available
ClosedChannelException - If the stream is closed
public String readStringByDelimiter(String delimiter,
                                    String encoding,
                                    int maxLength)
                             throws IOException,
                                    BufferUnderflowException,
                                    UnsupportedEncodingException,
                                    MaxReadSizeExceededException,
                                    ClosedChannelException
delimiter - the delimiterencoding - the encodingmaxLength - the max length of bytes that should be read. If the limit is exceeded a MaxReadSizeExceededException will been thrown
MaxReadSizeExceededException - If the max read length has been exceeded and the delimiter hasn’t been found
IOException - If some other I/O error occurs
UnsupportedEncodingException - If the given encoding is not supported
BufferUnderflowException - if not enough data is available
ClosedChannelException - If the stream is closed
public String readStringByLength(int length)
                          throws IOException,
                                 BufferUnderflowException,
                                 UnsupportedEncodingException,
                                 ClosedChannelException
length - the amount of bytes to read
IOException - If some other I/O error occurs
UnsupportedEncodingException - if the given encoding is not supported
IllegalArgumentException, - if the length parameter is negative
BufferUnderflowException - if not enough data is available
ClosedChannelException - If the stream is closed
public String readStringByLength(int length,
                                 String encoding)
                          throws IOException,
                                 BufferUnderflowException,
                                 UnsupportedEncodingException,
                                 ClosedChannelException
length - the amount of bytes to readencoding - the encoding
IOException - If some other I/O error occurs
UnsupportedEncodingException - if the given encoding is not supported
IllegalArgumentException, - if the length parameter is negative
BufferUnderflowException - if not enough data is available
ClosedChannelException - If the stream is closed
public long transferTo(WritableByteChannel target,
                       int length)
                throws IOException,
                       ClosedChannelException,
                       BufferUnderflowException,
                       ClosedChannelException
dataSink - the data sinklength - the size to transfer
ClosedChannelException - If either this channel or the target channel is closed
IOException - If some other I/O error occurs
BufferUnderflowException - if not enough data is available
ClosedChannelException - If the stream is closed
protected ByteBuffer readSingleByteBuffer(int length)
                                   throws IOException,
                                          ClosedChannelException,
                                          BufferUnderflowException,
                                          ClosedChannelException
length - the length
IOException - If some other I/O error occurs
BufferUnderflowException - if not enough data is available
ClosedChannelException - If the stream is closed
public final int write(byte b)
                throws IOException,
                       BufferOverflowException,
                       ClosedChannelException
b - the byte to write
BufferOverflowException - If the no enough space is available
IOException - If some other I/O error occurs
ClosedChannelException - If the stream is closed
public final int write(byte... bytes)
                throws IOException,
                       BufferOverflowException,
                       ClosedChannelException
bytes - the bytes to write
BufferOverflowException - If the no enough space is available
IOException - If some other I/O error occurs
ClosedChannelException - If the stream is closed
public final int write(byte[] bytes,
                       int offset,
                       int length)
                throws IOException,
                       BufferOverflowException,
                       ClosedChannelException
bytes - the bytes to writeoffset - The offset of the sub array 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 sub array 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.
BufferOverflowException - If the no enough space is available
IOException - If some other I/O error occurs
ClosedChannelException - If the stream is closed
public final int write(short s)
                throws IOException,
                       BufferOverflowException,
                       ClosedChannelException
s - the short value to write
BufferOverflowException - If the no enough space is available
IOException - If some other I/O error occurs
ClosedChannelException - If the stream is closed
public final int write(int i)
                throws IOException,
                       BufferOverflowException,
                       ClosedChannelException
i - the int value to write
BufferOverflowException - If the no enough space is available
IOException - If some other I/O error occurs
ClosedChannelException - If the stream is closed
public final int write(long l)
                throws IOException,
                       BufferOverflowException,
                       ClosedChannelException
l - the int value to write
BufferOverflowException - If the no enough space is available
IOException - If some other I/O error occurs
ClosedChannelException - If the stream is closed
public final int write(double d)
                throws IOException,
                       BufferOverflowException,
                       ClosedChannelException
d - the int value to write
BufferOverflowException - If the no enough space is available
IOException - If some other I/O error occurs
ClosedChannelException - If the stream is closed
public final int write(String message)
                throws IOException,
                       BufferOverflowException,
                       ClosedChannelException
message - the message to write
BufferOverflowException - If the no enough space is available
IOException - If some other I/O error occurs
ClosedChannelException - If the stream is closed
public final int write(String message,
                       String encoding)
                throws IOException,
                       BufferOverflowException,
                       ClosedChannelException
message - the message to writeencoding - the encoding
BufferOverflowException - If the no enough space is available
IOException - If some other I/O error occurs
ClosedChannelException - If the stream is closed
public final long write(List<ByteBuffer> buffers)
                 throws IOException,
                        BufferOverflowException,
                        ClosedChannelException
buffers - the bytes to write
BufferOverflowException - If the no enough space is available
IOException - If some other I/O error occurs
ClosedChannelException - If the stream is closed
public final long write(ByteBuffer[] srcs,
                        int offset,
                        int length)
                 throws IOException,
                        ClosedChannelException
GatheringByteChannel.write(ByteBuffer[], int, int)
IOException
ClosedChannelException
public final long write(ByteBuffer[] buffers)
                 throws IOException,
                        BufferOverflowException,
                        ClosedChannelException
GatheringByteChannel.write(ByteBuffer[])
IOException
BufferOverflowException
ClosedChannelException
public final int write(ByteBuffer buffer)
                throws IOException,
                       BufferOverflowException,
                       ClosedChannelException
WritableByteChannel.write(ByteBuffer)
write in interface WritableByteChannelIOException
BufferOverflowException
ClosedChannelException
protected void onPreWrite(int size)
                   throws BufferOverflowException
size - the size to write
BufferOverflowException - if the write buffer max size is exceeded
public final long transferFrom(FileChannel fileChannel)
                        throws ClosedChannelException,
                               IOException,
                               SocketTimeoutException,
                               ClosedChannelException
fileChannel - the file channel
BufferOverflowException - If the no enough space is available
IOException - If some other I/O error occurs
ClosedChannelException - If the stream is closed
SocketTimeoutException
public long transferFrom(ReadableByteChannel source)
                  throws IOException,
                         BufferOverflowException,
                         ClosedChannelException
source - the source channel
BufferOverflowException - If the no enough space is available
IOException - If some other I/O error occurs
ClosedChannelException - If the stream is closed
public final long transferFrom(ReadableByteChannel source,
                               int chunkSize)
                        throws IOException,
                               BufferOverflowException,
                               ClosedChannelException
source - the source channelchunkSize - the chunk size to use
BufferOverflowException - If the no enough space is available
IOException - If some other I/O error occurs
ClosedChannelException - If the stream is closedpublic final void markReadPosition()
public final void markWritePosition()
public final boolean resetToWriteMark()
public final boolean resetToReadMark()
public final void removeReadMark()
public final void removeWriteMark()
protected boolean reset()
protected void onWriteDataInserted()
                            throws IOException,
                                   ClosedChannelException
IOException - if an exception occurs
ClosedChannelException - if the stream is closedprotected final int getWriteBufferSize()
protected final boolean isWriteBufferEmpty()
protected ByteBuffer[] drainWriteQueue()
protected final boolean isReadBufferEmpty()
protected final void appendDataToReadBuffer(ByteBuffer[] data,
                                            int size)
data - the data to appendprotected final void appendDataToReadBuffer(ByteBuffer[] data)
protected void onPostAppend()
protected final String printReadBuffer(String encoding)
encoding - the encoding
protected final String printWriteBuffer(String encoding)
encoding - the encoding
| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||