org.xsocket
Interface IDataSource

Package class diagram package IDataSource
All Known Subinterfaces:
IBlockingConnection, INonBlockingConnection
All Known Implementing Classes:
BlockingConnection, NonBlockingConnection, UserDatagram

public interface IDataSource

A data source is an I/O resource capable of providing data.

Author:
grro@xsocket.org

Method Summary
 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
 ByteBuffer[] readByteBufferByLength(int length)
          read a ByteBuffer by using a length definition
 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[] readBytesByLength(int length)
          read bytes by using a length definition

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
 short readShort()
          read a short value
 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 readStringByLength(int length)
          read a string by using a length definition
 long transferTo(WritableByteChannel target, int length)
          transfer the data of the this source channel to the given data sink
 

Method Detail

read

int read(ByteBuffer buffer)
         throws IOException
see ReadableByteChannel.read(ByteBuffer)

Throws:
IOException

readByte

byte readByte()
              throws IOException
read a byte

Returns:
the byte value
Throws:
IOException - If an I/O error occurs

readShort

short readShort()
                throws IOException
read a short value

Returns:
the short value
Throws:
IOException - If an I/O error occurs

readInt

int readInt()
            throws IOException
read an int

Returns:
the int value
Throws:
IOException - If an I/O error occurs

readLong

long readLong()
              throws IOException
read a long

Returns:
the long value
Throws:
IOException - If an I/O error occurs

readDouble

double readDouble()
                  throws IOException
read a double

Returns:
the double value
Throws:
IOException - If an I/O error occurs

readBytesByLength

byte[] readBytesByLength(int length)
                         throws IOException
read bytes by using a length definition

For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes

Parameters:
length - the amount of bytes to read
Returns:
the read bytes
Throws:
IOException - If some other I/O error occurs
IllegalArgumentException - if the length parameter is negative

readByteBufferByDelimiter

ByteBuffer[] readByteBufferByDelimiter(String delimiter)
                                       throws IOException
read a ByteBuffer by using a delimiter. To avoid memory leaks the readByteBufferByDelimiter(String, int) method is generally preferable.

Parameters:
delimiter - the delimiter (by using the default encoding)
Returns:
the ByteBuffer
Throws:
IOException - If an I/O error occurs

readByteBufferByDelimiter

ByteBuffer[] readByteBufferByDelimiter(String delimiter,
                                       int maxLength)
                                       throws IOException,
                                              MaxReadSizeExceededException
read a ByteBuffer by using a delimiter

Parameters:
delimiter - the delimiter (by using the default encoding)
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
IOException - If some other I/O error occurs

readByteBufferByLength

ByteBuffer[] readByteBufferByLength(int length)
                                    throws IOException
read a ByteBuffer by using a length definition

Parameters:
length - the amount of bytes to read
Returns:
the ByteBuffer
Throws:
IOException - If some other I/O error occurs
IllegalArgumentException, - if the length parameter is negative

readStringByLength

String readStringByLength(int length)
                          throws IOException,
                                 BufferUnderflowException
read a string by using a length definition

Parameters:
length - the amount of bytes to read
Returns:
the string
Throws:
IOException - If some other I/O error occurs
UnsupportedEncodingException - if the given encoding is not supported
IllegalArgumentException, - if the length parameter is negative
BufferUnderflowException

readStringByDelimiter

String readStringByDelimiter(String delimiter)
                             throws IOException,
                                    UnsupportedEncodingException
read a string by using a delimiter

Parameters:
delimiter - the delimiter (by using the default encoding)
Returns:
the string
Throws:
IOException - If some other I/O error occurs
UnsupportedEncodingException - if the default encoding is not supported

readBytesByDelimiter

byte[] readBytesByDelimiter(String delimiter)
                            throws IOException
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 (by using the default encoding)
Returns:
the read bytes
Throws:
IOException - If an I/O error occurs

readBytesByDelimiter

byte[] readBytesByDelimiter(String delimiter,
                            int maxLength)
                            throws IOException,
                                   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 (by using the default encoding)
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
IOException - If some other I/O error occurs

readStringByDelimiter

String readStringByDelimiter(String delimiter,
                             int maxLength)
                             throws IOException,
                                    UnsupportedEncodingException,
                                    MaxReadSizeExceededException
read a string by using a delimiter

Parameters:
delimiter - the delimiter (by using the default encoding)
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
IOException - If some other I/O error occurs
UnsupportedEncodingException - If the given encoding is not supported

transferTo

long transferTo(WritableByteChannel target,
                int length)
                throws IOException,
                       ClosedChannelException
transfer the data of the this source channel to the given data sink

Parameters:
dataSink - the data sink
length - the size to transfer
Returns:
the number of transfered bytes
Throws:
ClosedChannelException - If either this channel or the target channel is closed
IOException - If some other I/O error occurs


Copyright 2010 xSocket.org