|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface IBlockingConnection
A connection which uses the underlying channel in a blocking manner. Every I/O operation
will block until it completes.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface org.xsocket.stream.IConnection |
---|
IConnection.FlushMode |
Field Summary | |
---|---|
static long |
INITIAL_RECEIVE_TIMEOUT
|
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. |
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. |
byte |
readByte()
receive a byte. the method will block, until data is available |
java.nio.ByteBuffer[] |
readByteBufferByDelimiter(java.lang.String delimiter)
receive a ByteBuffer. the method will block, until the delimiter has been read. |
java.nio.ByteBuffer[] |
readByteBufferByDelimiter(java.lang.String delimiter,
int maxLength)
receive a ByteBuffer. the method will block, until the delimiter has been read. |
java.nio.ByteBuffer[] |
readByteBufferByLength(int length)
receive a ByteBuffer. the method will block, until the required amount of bytes has been received For performance reasons, the ByteBuffer receiveByteBuffer method is generally preferable to get bytes |
byte[] |
readBytesByDelimiter(java.lang.String delimiter)
receive a byte array. the method will block, until the delimiter has been read. |
byte[] |
readBytesByDelimiter(java.lang.String delimiter,
int maxLength)
receive a byte array. the method will block, until the delimiter has been read. |
byte[] |
readBytesByLength(int length)
receive a byte array. the method will block, until the required amount of bytes has been received For performance reasons, the ByteBuffer receiveByteBuffer method is generally preferable to get bytes |
double |
readDouble()
receive a double. the method will block, until data is available |
int |
readInt()
receive an int. the method will block, until data is available |
long |
readLong()
receive a long. the method will block, until data is available |
java.lang.String |
readStringByDelimiter(java.lang.String delimiter)
receive a string. the method will block, until the delimiter has been read. |
java.lang.String |
readStringByDelimiter(java.lang.String delimiter,
int maxLength)
receive a string. the method will block, until the delimiter has been read. |
java.lang.String |
readStringByDelimiter(java.lang.String delimiter,
java.lang.String encoding)
receive a string. the method will block, until the delimiter has been read To avoid memory leaks the readStringByDelimiter(String, String) method is generally preferable |
java.lang.String |
readStringByDelimiter(java.lang.String delimiter,
java.lang.String encoding,
int maxLength)
receive a string. the method will block, until the delimiter has been read |
java.lang.String |
readStringByLength(int length)
receive a string. |
java.lang.String |
readStringByLength(int length,
java.lang.String encoding)
receive a string. |
IBlockingConnection |
setOption(java.lang.String name,
java.lang.Object value)
sets the value of a option |
void |
setReceiveTimeoutMillis(long timeout)
set the timeout for calling read methods in millis |
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 |
---|
static final long INITIAL_RECEIVE_TIMEOUT
Method Detail |
---|
void setReceiveTimeoutMillis(long timeout)
timeout
- the timeout in millisjava.lang.String readStringByDelimiter(java.lang.String delimiter) throws java.io.IOException, ClosedConnectionException, java.io.UnsupportedEncodingException, java.net.SocketTimeoutException
readStringByDelimiter(String, int)
method is generally preferable
readStringByDelimiter
in interface IConnection
readStringByDelimiter
in interface IDataSource
delimiter
- the delimiter
ClosedConnectionException
- If the underlying socket is already closed
java.io.IOException
- If some other I/O error occurs
java.net.SocketTimeoutException
- If the receive timeout has been reached
java.io.UnsupportedEncodingException
- if the default encoding is not supportedjava.lang.String readStringByDelimiter(java.lang.String delimiter, int maxLength) throws java.io.IOException, ClosedConnectionException, java.io.UnsupportedEncodingException, java.net.SocketTimeoutException, MaxReadSizeExceededException
readStringByDelimiter
in interface IConnection
readStringByDelimiter
in interface IDataSource
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
ClosedConnectionException
- If the underlying socket is already closed
java.io.IOException
- If some other I/O error occurs
java.net.SocketTimeoutException
- If the receive timeout has been reached
java.io.UnsupportedEncodingException
- if the default encoding is not supportedjava.lang.String readStringByDelimiter(java.lang.String delimiter, java.lang.String encoding) throws java.io.IOException, ClosedConnectionException, java.io.UnsupportedEncodingException, java.net.SocketTimeoutException
readStringByDelimiter(String, String)
method is generally preferable
readStringByDelimiter
in interface IConnection
delimiter
- the delimiterencoding
- the encoding to use
java.net.SocketTimeoutException
- If the receive timeout has been reached
java.io.IOException
- If some other I/O error occurs
java.io.UnsupportedEncodingException
- If the given encoding is not supported
ClosedConnectionException
- If the underlying socket is already closedjava.lang.String readStringByDelimiter(java.lang.String delimiter, java.lang.String encoding, int maxLength) throws java.io.IOException, ClosedConnectionException, java.io.UnsupportedEncodingException, java.net.SocketTimeoutException, MaxReadSizeExceededException
readStringByDelimiter
in interface IConnection
readStringByDelimiter
in interface IDataSource
delimiter
- the delimiterencoding
- the encoding to usemaxLength
- 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 * @throws ClosedConnectionException If the underlying socket is already closed
java.net.SocketTimeoutException
- If the receive timeout has been reached
java.io.IOException
- If some other I/O error occurs
java.io.UnsupportedEncodingException
- If the given encoding is not supported
ClosedConnectionException
- If the underlying socket is already closedjava.lang.String readStringByLength(int length) throws java.io.IOException, ClosedConnectionException, java.net.SocketTimeoutException
readStringByLength
in interface IConnection
readStringByLength
in interface IDataSource
length
- the number of bytes to read
java.net.SocketTimeoutException
- If the receive timeout has been reached
ClosedConnectionException
- If the underlying socket is already closed
java.io.IOException
- If some other I/O error occursjava.lang.String readStringByLength(int length, java.lang.String encoding) throws java.io.IOException, ClosedConnectionException, java.net.SocketTimeoutException
readStringByLength
in interface IConnection
readStringByLength
in interface IDataSource
length
- the number of bytes to readencoding
- the encoding
java.net.SocketTimeoutException
- If the receive timeout has been reached
ClosedConnectionException
- If the underlying socket is already closed
java.io.IOException
- If some other I/O error occursjava.nio.ByteBuffer[] readByteBufferByDelimiter(java.lang.String delimiter) throws java.io.IOException, ClosedConnectionException, java.net.SocketTimeoutException
readByteBufferByDelimiter(String, int)
method is generally preferable
readByteBufferByDelimiter
in interface IConnection
delimiter
- the delimiter
MaxReadSizeExceededException
- If the max read length has been exceeded and the delimiter hasn’t been found
java.net.SocketTimeoutException
- If the receive timeout has been reached
ClosedConnectionException
- If the underlying socket is already closed
java.io.IOException
- If some other I/O error occursjava.nio.ByteBuffer[] readByteBufferByDelimiter(java.lang.String delimiter, int maxLength) throws java.io.IOException, ClosedConnectionException, java.net.SocketTimeoutException, MaxReadSizeExceededException
readByteBufferByDelimiter
in interface IConnection
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
java.net.SocketTimeoutException
- If the receive timeout has been reached
ClosedConnectionException
- If the underlying socket is already closed
java.io.IOException
- If some other I/O error occursjava.nio.ByteBuffer[] readByteBufferByLength(int length) throws java.io.IOException, ClosedConnectionException, java.net.SocketTimeoutException
readByteBufferByLength
in interface IConnection
length
- the number of bytes to read
java.net.SocketTimeoutException
- If the receive timeout has been reached
ClosedConnectionException
- If the underlying socket is already closed
java.io.IOException
- If some other I/O error occursbyte[] readBytesByDelimiter(java.lang.String delimiter) throws java.io.IOException, ClosedConnectionException, java.net.SocketTimeoutException
readBytesByDelimiter(String, int)
method is generally preferable
readBytesByDelimiter
in interface IConnection
delimiter
- the delimiter
java.net.SocketTimeoutException
- If the receive timeout has been reached
ClosedConnectionException
- If the underlying socket is already closed
java.io.IOException
- If some other I/O error occursbyte[] readBytesByDelimiter(java.lang.String delimiter, int maxLength) throws java.io.IOException, ClosedConnectionException, java.net.SocketTimeoutException, MaxReadSizeExceededException
readBytesByDelimiter
in interface IConnection
readBytesByDelimiter
in interface IDataSource
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
java.net.SocketTimeoutException
- If the receive timeout has been reached
ClosedConnectionException
- If the underlying socket is already closed
java.io.IOException
- If some other I/O error occursint getIndexOf(java.lang.String str) throws java.io.IOException, ClosedConnectionException, java.net.SocketTimeoutException
getIndexOf
in interface IConnection
str
- any string
ClosedConnectionException
- If the underlying socket is already closed
java.io.IOException
- If some other I/O error occurs
java.net.SocketTimeoutException
- If the receive timeout has been reachedint getIndexOf(java.lang.String str, int maxLength) throws java.io.IOException, ClosedConnectionException, MaxReadSizeExceededException, java.net.SocketTimeoutException
getIndexOf
in interface IConnection
str
- any stringmaxLength
- the max length of bytes that should be read. If the limit is exceeded a MaxReadSizeExceededException will been thrown
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.net.SocketTimeoutException
- If the receive timeout has been reachedbyte[] readBytesByLength(int length) throws java.io.IOException, ClosedConnectionException, java.net.SocketTimeoutException
readBytesByLength
in interface IConnection
readBytesByLength
in interface IDataSource
length
- the number of bytes to read
java.net.SocketTimeoutException
- If the receive timeout has been reached
ClosedConnectionException
- If the underlying socket is already closed
java.io.IOException
- If some other I/O error occursint readInt() throws java.io.IOException, ClosedConnectionException, java.net.SocketTimeoutException
readInt
in interface IConnection
readInt
in interface IDataSource
java.net.SocketTimeoutException
- If the receive timeout has been reached
ClosedConnectionException
- If the underlying socket is already closed
java.io.IOException
- If some other I/O error occurslong readLong() throws java.io.IOException, ClosedConnectionException, java.net.SocketTimeoutException
readLong
in interface IConnection
readLong
in interface IDataSource
java.net.SocketTimeoutException
- If the receive timeout has been reached
ClosedConnectionException
- If the underlying socket is already closed
java.io.IOException
- If some other I/O error occursdouble readDouble() throws java.io.IOException, ClosedConnectionException, java.net.SocketTimeoutException
readDouble
in interface IConnection
readDouble
in interface IDataSource
java.net.SocketTimeoutException
- If the receive timeout has been reached
ClosedConnectionException
- If the underlying socket is already closed
java.io.IOException
- If some other I/O error occursbyte readByte() throws java.io.IOException, ClosedConnectionException, java.net.SocketTimeoutException
readByte
in interface IConnection
readByte
in interface IDataSource
java.net.SocketTimeoutException
- If the receive timeout has been reached
ClosedConnectionException
- If the underlying socket is already closed
java.io.IOException
- If some other I/O error occursint write(java.lang.String message, java.lang.String encoding) throws ClosedConnectionException, java.io.IOException, java.net.SocketTimeoutException
write
in interface IConnection
write
in interface IDataSink
message
- the message to sendencoding
- the encoding which should be used th encode the chars into byte (e.g. `US-ASCII` or `UTF-8`)
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 closedint write(java.lang.String message) throws ClosedConnectionException, java.io.IOException, java.net.SocketTimeoutException
write
in interface IConnection
write
in interface IDataSink
message
- the message to send
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 closedint write(byte b) throws ClosedConnectionException, java.io.IOException, java.net.SocketTimeoutException
write
in interface IConnection
write
in interface IDataSink
b
- the byte to send
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 closedint write(byte... bytes) throws ClosedConnectionException, java.io.IOException, java.net.SocketTimeoutException
write
in interface IConnection
write
in interface IDataSink
bytes
- the bytes to send
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 closedint write(byte[] bytes, int offset, int length) throws ClosedConnectionException, java.io.IOException, java.net.SocketTimeoutException
write
in interface IConnection
write
in interface IDataSink
bytes
- the bytes to sendoffset
- 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.
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 closedint write(java.nio.ByteBuffer buffer) throws ClosedConnectionException, java.io.IOException, java.net.SocketTimeoutException
write
in interface IConnection
write
in interface IDataSink
write
in interface java.nio.channels.WritableByteChannel
buffer
- the bytes to send
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 closedlong write(java.nio.ByteBuffer[] buffers) throws ClosedConnectionException, java.io.IOException, java.net.SocketTimeoutException
write
in interface java.nio.channels.GatheringByteChannel
write
in interface IConnection
write
in interface IDataSink
buffers
- the bytes to send
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 closedint write(int i) throws ClosedConnectionException, java.io.IOException, java.net.SocketTimeoutException
write
in interface IConnection
write
in interface IDataSink
i
- the int value to send
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 closedint write(long l) throws ClosedConnectionException, java.io.IOException, java.net.SocketTimeoutException
write
in interface IConnection
write
in interface IDataSink
l
- the int value to send
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 closedint write(double d) throws ClosedConnectionException, java.io.IOException, java.net.SocketTimeoutException
write
in interface IConnection
write
in interface IDataSink
d
- the int value to send
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 closedvoid flush() throws ClosedConnectionException, java.io.IOException, java.net.SocketTimeoutException
flush
in interface java.io.Flushable
flush
in interface IConnection
java.io.IOException
- If some other I/O error occurs
java.net.SocketTimeoutException
- If the timeout has been reached
ClosedConnectionException
- if the underlying channel is closedIBlockingConnection setOption(java.lang.String name, java.lang.Object value) throws java.io.IOException
setOption
in interface IConnection
name
- the name of the optionvalue
- the value of the option
java.io.IOException
- In an I/O error occurs
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |