|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.xsocket.stream.BlockingConnection
public final class BlockingConnection
Implementation of the IBlockingConnection
interface.
A newly created connection is in the open state. The methods of this class are not thread-safe.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface org.xsocket.stream.IConnection |
---|
IConnection.FlushMode |
Field Summary |
---|
Fields inherited from interface org.xsocket.stream.IBlockingConnection |
---|
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 |
Constructor Summary | |
---|---|
BlockingConnection(java.net.InetAddress address,
int port)
constructor |
|
BlockingConnection(java.net.InetAddress address,
int port,
java.util.Map<java.lang.String,java.lang.Object> options)
Deprecated. |
|
BlockingConnection(java.net.InetAddress address,
int port,
java.util.Map<java.lang.String,java.lang.Object> options,
javax.net.ssl.SSLContext sslContext,
boolean sslOn)
constructor |
|
BlockingConnection(java.net.InetAddress address,
int port,
javax.net.ssl.SSLContext sslContext,
boolean sslOn)
constructor |
|
BlockingConnection(java.net.InetAddress address,
int port,
StreamSocketConfiguration socketConf)
Deprecated. |
|
BlockingConnection(java.net.InetAddress address,
int port,
StreamSocketConfiguration socketConf,
javax.net.ssl.SSLContext sslContext,
boolean sslOn)
Deprecated. |
|
BlockingConnection(java.lang.String hostname,
int port)
constructor. |
|
BlockingConnection(java.lang.String hostname,
int port,
java.util.Map<java.lang.String,java.lang.Object> options)
constructor. |
|
BlockingConnection(java.lang.String hostname,
int port,
java.util.Map<java.lang.String,java.lang.Object> options,
javax.net.ssl.SSLContext sslContext,
boolean sslOn)
constructor |
|
BlockingConnection(java.lang.String hostname,
int port,
javax.net.ssl.SSLContext sslContext,
boolean sslOn)
constructor |
|
BlockingConnection(java.lang.String hostname,
int port,
StreamSocketConfiguration socketConfiguration)
Deprecated. |
|
BlockingConnection(java.lang.String hostname,
int port,
StreamSocketConfiguration socketConf,
javax.net.ssl.SSLContext sslContext,
boolean sslOn)
Deprecated. |
Method Summary | |
---|---|
void |
activateSecuredMode()
ad hoc activation of a secured mode (SSL). |
java.lang.Object |
attach(java.lang.Object obj)
|
java.lang.Object |
attachment()
|
void |
close()
|
void |
flush()
flush the send buffer. |
java.lang.Object |
getAttachment()
Retrieves the current attachment. |
boolean |
getAutoflush()
get autoflush |
int |
getConnectionTimeoutSec()
gets the connection timeout |
java.lang.String |
getDefaultEncoding()
gets the default encoding for this connection (used by string related methods like readString...) |
IConnection.FlushMode |
getFlushmode()
get the flushmode |
java.lang.String |
getId()
returns the id |
int |
getIdleTimeoutSec()
returns the idle timeout in sec. |
int |
getIndexOf(java.lang.String str)
Returns the index of the first occurrence of the given string. |
int |
getIndexOf(java.lang.String str,
int maxLength)
Returns the index of the first occurrence of the given string. |
int |
getIndexOf(java.lang.String str,
java.lang.String encoding,
int maxLength)
Returns the index of the first occurrence of the given string. |
java.net.InetAddress |
getLocalAddress()
returns the local address |
int |
getLocalPort()
returns the local port |
java.lang.Object |
getOption(java.lang.String name)
returns the value of a option |
java.util.Map<java.lang.String,java.lang.Class> |
getOptions()
Returns an unmodifiable map of the options supported by this endpoint. |
int |
getPendingWriteDataSize()
returns the size of the data which have already been written, but not yet transferred to the underlying socket. |
java.net.InetAddress |
getRemoteAddress()
returns the remote address |
int |
getRemotePort()
returns the port of the remote endpoint |
int |
indexOf(java.lang.String str)
Deprecated. uses getIndexOf instead |
boolean |
isOpen()
returns, if the connection is open. |
void |
markReadPosition()
Marks the present read position in the connection. |
void |
markWritePosition()
Marks the present write position in the connection. |
void |
onWriteException(java.io.IOException ioException)
|
void |
onWritten()
|
int |
read(java.nio.ByteBuffer buffer)
. |
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[] |
readByteBufferByDelimiter(java.lang.String delimiter,
java.lang.String encoding,
int maxLength)
read a ByteBuffer by using a delimiter For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes |
java.nio.ByteBuffer[] |
readByteBufferByLength(int length)
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[] |
readBytesByDelimiter(java.lang.String delimiter,
java.lang.String encoding,
int maxLength)
read a byte array by using a delimiter For performance reasons, the ByteBuffer readByteBuffer method is generally preferable to get bytes |
byte[] |
readBytesByLength(int length)
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 |
short |
readShort()
read a short value |
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 IBlockingConnection.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. |
void |
removeReadMark()
remove the mark the present read position in the connection. |
void |
removeWriteMark()
remove the mark the present write position in the connection. |
boolean |
resetToReadMark()
Resets to the marked read position. |
boolean |
resetToWriteMark()
Resets to the marked write position. |
void |
resumeRead()
resume reading data from the underlying subsystem |
void |
setAttachment(java.lang.Object obj)
Attaches the given object to this connection |
void |
setAutoflush(boolean autoflush)
set autoflush. |
void |
setConnectionTimeoutSec(int timeoutSec)
sets the max time for a connections. |
void |
setDefaultEncoding(java.lang.String defaultEncoding)
sets the default encoding for this connection (used by string related methods like readString...) |
void |
setFlushmode(IConnection.FlushMode flushMode)
set the flushmode |
void |
setIdleTimeoutSec(int timeoutInSec)
sets the idle timeout in sec |
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 |
void |
suspendRead()
suspend reading data from the underlying subsystem |
java.lang.String |
toString()
|
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. |
long |
write(java.nio.ByteBuffer[] srcs,
int offset,
int length)
|
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(short s)
writes a short to the data sink |
int |
write(java.lang.String s)
sends a message to the remote endpoint by using the connection default encoding |
int |
write(java.lang.String s,
java.lang.String encoding)
sends a message to the remote endpoint |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface org.xsocket.stream.IBlockingConnection |
---|
flush, write, write, write, write, write, write, write, write, write, write |
Methods inherited from interface org.xsocket.stream.IConnection |
---|
activateSecuredMode, attach, attachment, getAttachment, getAutoflush, getConnectionTimeoutSec, getDefaultEncoding, getId, getIdleTimeoutSec, getLocalAddress, getLocalPort, getOption, getOptions, getPendingWriteDataSize, getRemoteAddress, getRemotePort, isOpen, markReadPosition, markWritePosition, removeReadMark, removeWriteMark, resetToReadMark, resetToWriteMark, resumeRead, setAttachment, setAutoflush, setConnectionTimeoutSec, setDefaultEncoding, setIdleTimeoutSec, suspendRead |
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 |
Constructor Detail |
---|
public BlockingConnection(java.lang.String hostname, int port) throws java.io.IOException
hostname
- the remote hostport
- the port of the remote host to connect
java.io.IOException
- If some other I/O error occurspublic BlockingConnection(java.lang.String hostname, int port, StreamSocketConfiguration socketConfiguration) throws java.io.IOException
hostname
- the remote hostport
- the port of the remote host to connectsocketConfiguration
- the socket configuration
java.io.IOException
- If some other I/O error occurspublic BlockingConnection(java.lang.String hostname, int port, java.util.Map<java.lang.String,java.lang.Object> options) throws java.io.IOException
hostname
- the remote hostport
- the port of the remote host to connectoptions
- the socket options
java.io.IOException
- If some other I/O error occurspublic BlockingConnection(java.net.InetAddress address, int port) throws java.io.IOException
address
- the remote host addressport
- the remote host port
java.io.IOException
- If some other I/O error occurspublic BlockingConnection(java.net.InetAddress address, int port, StreamSocketConfiguration socketConf) throws java.io.IOException
address
- the remote host addressport
- the remote host portsocketConf
- the socket configuration
java.io.IOException
- If some other I/O error occurspublic BlockingConnection(java.net.InetAddress address, int port, java.util.Map<java.lang.String,java.lang.Object> options) throws java.io.IOException
address
- the remote host addressport
- the remote host portoptions
- the socket options
java.io.IOException
- If some other I/O error occurspublic BlockingConnection(java.net.InetAddress address, int port, javax.net.ssl.SSLContext sslContext, boolean sslOn) throws java.io.IOException
address
- the remote host nameport
- the remote host portsslContext
- the sslContext to usesslOn
- true, activate SSL mode. false, ssl can be activated by user (see IConnection.activateSecuredMode()
)
java.io.IOException
- If some other I/O error occurspublic BlockingConnection(java.net.InetAddress address, int port, StreamSocketConfiguration socketConf, javax.net.ssl.SSLContext sslContext, boolean sslOn) throws java.io.IOException
address
- the remote host nameport
- the remote host portsocketConf
- the socket configurationsslContext
- the sslContext to usesslOn
- true, activate SSL mode. false, ssl can be activated by user (see IConnection.activateSecuredMode()
)
java.io.IOException
- If some other I/O error occurspublic BlockingConnection(java.net.InetAddress address, int port, java.util.Map<java.lang.String,java.lang.Object> options, javax.net.ssl.SSLContext sslContext, boolean sslOn) throws java.io.IOException
address
- the remote host nameport
- the remote host portoptions
- the socket optionssslContext
- the sslContext to usesslOn
- true, activate SSL mode. false, ssl can be activated by user (see IConnection.activateSecuredMode()
)
java.io.IOException
- If some other I/O error occurspublic BlockingConnection(java.lang.String hostname, int port, javax.net.ssl.SSLContext sslContext, boolean sslOn) throws java.io.IOException
hostname
- the remote host nameport
- the remote host portsslContext
- the sslContext to usesslOn
- true, activate SSL mode. false, ssl can be activated by user (see IConnection.activateSecuredMode()
)
* @throws IOException If some other I/O error occurs
java.io.IOException
public BlockingConnection(java.lang.String hostname, int port, StreamSocketConfiguration socketConf, javax.net.ssl.SSLContext sslContext, boolean sslOn) throws java.io.IOException
hostname
- the remote host nameport
- the remote host portsocketConf
- the socket configurationsslContext
- the sslContext to usesslOn
- true, activate SSL mode. false, ssl can be activated by user (see IConnection.activateSecuredMode()
)
java.io.IOException
- If some other I/O error occurspublic BlockingConnection(java.lang.String hostname, int port, java.util.Map<java.lang.String,java.lang.Object> options, javax.net.ssl.SSLContext sslContext, boolean sslOn) throws java.io.IOException
hostname
- the remote host nameport
- the remote host portoption
- the socket optionssslContext
- the sslContext to usesslOn
- true, activate SSL mode. false, ssl can be activated by user (see IConnection.activateSecuredMode()
)
java.io.IOException
- If some other I/O error occursMethod Detail |
---|
public byte readByte() throws java.io.IOException, ClosedConnectionException, java.net.SocketTimeoutException
readByte
in interface IDataSource
readByte
in interface IBlockingConnection
readByte
in interface IConnection
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 occurspublic final void setReceiveTimeoutMillis(long timeout)
setReceiveTimeoutMillis
in interface IBlockingConnection
timeout
- the timeout in millispublic java.nio.ByteBuffer[] readByteBufferByDelimiter(java.lang.String delimiter) throws java.io.IOException, ClosedConnectionException, java.net.SocketTimeoutException
IBlockingConnection.readByteBufferByDelimiter(String, int)
method is generally preferable
readByteBufferByDelimiter
in interface IBlockingConnection
readByteBufferByDelimiter
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 occurspublic java.nio.ByteBuffer[] readByteBufferByDelimiter(java.lang.String delimiter, int maxLength) throws java.io.IOException, ClosedConnectionException, java.net.SocketTimeoutException, MaxReadSizeExceededException
readByteBufferByDelimiter
in interface IBlockingConnection
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
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 occurs
MaxReadSizeExceededException
- If the max read length has been exceeded and the delimiter hasn’t been foundpublic java.nio.ByteBuffer[] readByteBufferByDelimiter(java.lang.String delimiter, java.lang.String encoding, int maxLength) throws java.io.IOException, ClosedConnectionException, MaxReadSizeExceededException
readByteBufferByDelimiter
in interface IConnection
delimiter
- the delimiterencoding
- the encoding of the delimitermaxLength
- 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 foundpublic java.nio.ByteBuffer[] readByteBufferByLength(int length) throws java.io.IOException, ClosedConnectionException, java.net.SocketTimeoutException
readByteBufferByLength
in interface IBlockingConnection
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 occurspublic byte[] readBytesByDelimiter(java.lang.String delimiter) throws java.io.IOException, ClosedConnectionException, java.net.SocketTimeoutException
IBlockingConnection.readBytesByDelimiter(String, int)
method is generally preferable
readBytesByDelimiter
in interface IBlockingConnection
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 occurspublic byte[] readBytesByDelimiter(java.lang.String delimiter, int maxLength) throws java.io.IOException, ClosedConnectionException, java.net.SocketTimeoutException, MaxReadSizeExceededException
readBytesByDelimiter
in interface IDataSource
readBytesByDelimiter
in interface IBlockingConnection
readBytesByDelimiter
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
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 occurs
MaxReadSizeExceededException
- If the max read length has been exceeded and the delimiter hasn’t been foundpublic byte[] readBytesByDelimiter(java.lang.String delimiter, java.lang.String encoding, int maxLength) throws java.io.IOException, ClosedConnectionException, MaxReadSizeExceededException
readBytesByDelimiter
in interface IConnection
delimiter
- the delimiterencoding
- the encoding of the delimitermaxLength
- 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 foundpublic byte[] readBytesByLength(int length) throws java.io.IOException, ClosedConnectionException, java.net.SocketTimeoutException
readBytesByLength
in interface IDataSource
readBytesByLength
in interface IBlockingConnection
readBytesByLength
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 occurspublic double readDouble() throws java.io.IOException, ClosedConnectionException, java.net.SocketTimeoutException
readDouble
in interface IDataSource
readDouble
in interface IBlockingConnection
readDouble
in interface IConnection
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 occurspublic int readInt() throws java.io.IOException, ClosedConnectionException, java.net.SocketTimeoutException
readInt
in interface IDataSource
readInt
in interface IBlockingConnection
readInt
in interface IConnection
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 occurspublic short readShort() throws java.io.IOException, ClosedConnectionException, java.net.SocketTimeoutException
readShort
in interface IDataSource
java.io.IOException
- If some other I/O error occurs
ClosedConnectionException
java.net.SocketTimeoutException
public final int read(java.nio.ByteBuffer buffer) throws java.io.IOException
read
in interface java.nio.channels.ReadableByteChannel
java.io.IOException
public long readLong() throws java.io.IOException, ClosedConnectionException, java.net.SocketTimeoutException
readLong
in interface IDataSource
readLong
in interface IBlockingConnection
readLong
in interface IConnection
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 occurspublic java.lang.String readStringByDelimiter(java.lang.String delimiter) throws java.io.IOException, ClosedConnectionException, java.io.UnsupportedEncodingException, java.net.SocketTimeoutException
IBlockingConnection.readStringByDelimiter(String, int)
method is generally preferable
readStringByDelimiter
in interface IDataSource
readStringByDelimiter
in interface IBlockingConnection
readStringByDelimiter
in interface IConnection
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 supportedpublic java.lang.String readStringByDelimiter(java.lang.String delimiter, int maxLength) throws java.io.IOException, ClosedConnectionException, java.io.UnsupportedEncodingException, java.net.SocketTimeoutException, MaxReadSizeExceededException
readStringByDelimiter
in interface IDataSource
readStringByDelimiter
in interface IBlockingConnection
readStringByDelimiter
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
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 supported
MaxReadSizeExceededException
- If the max read length has been exceeded and the delimiter hasn’t been foundpublic java.lang.String readStringByDelimiter(java.lang.String delimiter, java.lang.String encoding) throws java.io.IOException, ClosedConnectionException, java.io.UnsupportedEncodingException, java.net.SocketTimeoutException
IBlockingConnection.readStringByDelimiter(String, String)
method is generally preferable
readStringByDelimiter
in interface IBlockingConnection
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 closedpublic java.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 IDataSource
readStringByDelimiter
in interface IBlockingConnection
readStringByDelimiter
in interface IConnection
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
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 closed
MaxReadSizeExceededException
- If the max read length has been exceeded and the delimiter hasn’t been found * @throws ClosedConnectionException If the underlying socket is already closedpublic int getIndexOf(java.lang.String str) throws java.io.IOException, ClosedConnectionException, java.net.SocketTimeoutException
getIndexOf
in interface IBlockingConnection
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 reachedpublic int getIndexOf(java.lang.String str, int maxLength) throws java.io.IOException, ClosedConnectionException, MaxReadSizeExceededException, java.net.SocketTimeoutException
getIndexOf
in interface IBlockingConnection
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
java.net.SocketTimeoutException
- If the receive timeout has been reached
MaxReadSizeExceededException
- If the max read length has been exceeded and the delimiter hasn’t been foundpublic int getIndexOf(java.lang.String str, java.lang.String encoding, int maxLength) throws java.io.IOException, ClosedConnectionException, MaxReadSizeExceededException
getIndexOf
in interface IConnection
str
- any stringencoding
- the encoding of the 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 foundpublic java.lang.String readStringByLength(int length) throws java.io.IOException, ClosedConnectionException, java.net.SocketTimeoutException
readStringByLength
in interface IDataSource
readStringByLength
in interface IBlockingConnection
readStringByLength
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 occurspublic java.lang.String readStringByLength(int length, java.lang.String encoding) throws java.io.IOException, ClosedConnectionException, java.net.SocketTimeoutException
readStringByLength
in interface IDataSource
readStringByLength
in interface IBlockingConnection
readStringByLength
in interface IConnection
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 occurspublic IBlockingConnection setOption(java.lang.String name, java.lang.Object value) throws java.io.IOException
setOption
in interface IBlockingConnection
setOption
in interface IConnection
name
- the name of the optionvalue
- the value of the option
java.io.IOException
- In an I/O error occurspublic final int getPendingWriteDataSize()
getPendingWriteDataSize
in interface IConnection
public final void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.nio.channels.Channel
java.io.IOException
public final boolean isOpen()
IDataHandler.onData(INonBlockingConnection)
isOpen
in interface java.nio.channels.Channel
isOpen
in interface IConnection
public void suspendRead() throws java.io.IOException
suspendRead
in interface IConnection
java.io.IOException
- If some other I/O error occurspublic void resumeRead() throws java.io.IOException
resumeRead
in interface IConnection
java.io.IOException
- If some other I/O error occurspublic void flush() throws ClosedConnectionException, java.io.IOException
flush
in interface java.io.Flushable
flush
in interface IConnection
ClosedConnectionException
- if the underlying channel is closed
java.io.IOException
- If some other I/O error occurspublic final void setFlushmode(IConnection.FlushMode flushMode)
flushMode
- the flushmodepublic final IConnection.FlushMode getFlushmode()
public void setIdleTimeoutSec(int timeoutInSec)
setIdleTimeoutSec
in interface IConnection
timeoutInSec
- idle timeout in secpublic void setConnectionTimeoutSec(int timeoutSec)
setConnectionTimeoutSec
in interface IConnection
timeoutSec
- the connection timeout in secpublic int getConnectionTimeoutSec()
getConnectionTimeoutSec
in interface IConnection
public int getIdleTimeoutSec()
getIdleTimeoutSec
in interface IConnection
public final java.lang.String getDefaultEncoding()
getDefaultEncoding
in interface IConnection
public final void setDefaultEncoding(java.lang.String defaultEncoding)
setDefaultEncoding
in interface IConnection
defaultEncoding
- the default encodingpublic final void setAutoflush(boolean autoflush)
setAutoflush
in interface IConnection
autoflush
- true if autoflush should be activatedpublic final boolean getAutoflush()
getAutoflush
in interface IConnection
public final java.lang.String getId()
getId
in interface IConnection
public final java.net.InetAddress getLocalAddress()
getLocalAddress
in interface IConnection
public final int getLocalPort()
getLocalPort
in interface IConnection
public final java.net.InetAddress getRemoteAddress()
getRemoteAddress
in interface IConnection
public final int getRemotePort()
getRemotePort
in interface IConnection
public void activateSecuredMode() throws java.io.IOException
activateSecuredMode
in interface IConnection
java.io.IOException
- If some other I/O error occurspublic final int write(java.lang.String s) throws ClosedConnectionException, java.io.IOException
write
in interface IDataSink
write
in interface IConnection
s
- the message to send
ClosedConnectionException
- if the underlying channel is closed
java.io.IOException
- If some other I/O error occurspublic final int write(java.lang.String s, java.lang.String encoding) throws ClosedConnectionException, java.io.IOException
write
in interface IDataSink
write
in interface IConnection
s
- the message to sendencoding
- the encoding which should be used th encode the chars into byte (e.g. `US-ASCII` or `UTF-8`)
ClosedConnectionException
- if the underlying channel is closed
java.io.IOException
- If some other I/O error occurspublic final int write(byte b) throws ClosedConnectionException, java.io.IOException
write
in interface IDataSink
write
in interface IConnection
b
- the byte to send
ClosedConnectionException
- if the underlying channel is closed
java.io.IOException
- If some other I/O error occurspublic final int write(byte... bytes) throws ClosedConnectionException, java.io.IOException
write
in interface IDataSink
write
in interface IConnection
bytes
- the bytes to send
ClosedConnectionException
- if the underlying channel is closed
java.io.IOException
- If some other I/O error occurspublic final int write(byte[] bytes, int offset, int length) throws ClosedConnectionException, java.io.IOException
write
in interface IDataSink
write
in interface IConnection
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.
ClosedConnectionException
- if the underlying channel is closed
java.io.IOException
- If some other I/O error occurspublic final long write(java.nio.ByteBuffer[] buffers) throws ClosedConnectionException, java.io.IOException
IConnection.INITIAL_AUTOFLUSH
) the behaviour is
according to the WritableByteChannel
specification. In case of
user managed flushing (autoflush is off) the passed over buffers will
only be queued internally and written after flushing the connection.
write
in interface java.nio.channels.GatheringByteChannel
write
in interface IDataSink
write
in interface IConnection
buffers
- the bytes to send
ClosedConnectionException
- if the underlying channel is closed
java.io.IOException
- If some other I/O error occurspublic final int write(java.nio.ByteBuffer buffer) throws ClosedConnectionException, java.io.IOException
IConnection.INITIAL_AUTOFLUSH
) the behaviour is
according to the WritableByteChannel
specification. In case of
user managed flushing (autoflush is off) the passed over buffers will
only be queued internally and written after flushing the connection.
write
in interface java.nio.channels.WritableByteChannel
write
in interface IDataSink
write
in interface IConnection
buffer
- the bytes to send
ClosedConnectionException
- if the underlying channel is closed
java.io.IOException
- If some other I/O error occurspublic final int write(int i) throws ClosedConnectionException, java.io.IOException
write
in interface IDataSink
write
in interface IConnection
i
- the int value to send
ClosedConnectionException
- if the underlying channel is closed
java.io.IOException
- If some other I/O error occurspublic final int write(short s) throws ClosedConnectionException, java.io.IOException
write
in interface IDataSink
s
- the short value to write
java.io.IOException
- If some other I/O error occurs
ClosedConnectionException
public final int write(long l) throws ClosedConnectionException, java.io.IOException
write
in interface IDataSink
write
in interface IConnection
l
- the int value to send
ClosedConnectionException
- if the underlying channel is closed
java.io.IOException
- If some other I/O error occurspublic final int write(double d) throws ClosedConnectionException, java.io.IOException
write
in interface IDataSink
write
in interface IConnection
d
- the int value to send
ClosedConnectionException
- if the underlying channel is closed
java.io.IOException
- If some other I/O error occurspublic final long write(java.nio.ByteBuffer[] srcs, int offset, int length) throws java.io.IOException
write
in interface java.nio.channels.GatheringByteChannel
java.io.IOException
public int indexOf(java.lang.String str)
str
- any string
public final java.lang.Object attach(java.lang.Object obj)
attach
in interface IConnection
public final java.lang.Object attachment()
attachment
in interface IConnection
public final void setAttachment(java.lang.Object obj)
setAttachment
in interface IConnection
obj
- The object to be attached; may be nullpublic final java.lang.Object getAttachment()
getAttachment
in interface IConnection
public void markReadPosition()
markReadPosition
in interface IConnection
public void markWritePosition()
... con.setAutoflush(false); con.markWritePosition(); // mark current position con.write((int) 0); // write "emtpy" length field int written = con.write("hello world"); written += con.write(" it’s nice to be here"); ... con.resetToWriteMark(); // return to length field position con.write(written); // and update it con.flush(); // flush (marker will be removed implicit) … *
markWritePosition
in interface IConnection
public boolean resetToWriteMark()
resetToWriteMark
in interface IConnection
public boolean resetToReadMark()
resetToReadMark
in interface IConnection
public void removeReadMark()
removeReadMark
in interface IConnection
public void removeWriteMark()
removeWriteMark
in interface IConnection
public void onWritten()
public void onWriteException(java.io.IOException ioException)
public final java.lang.Object getOption(java.lang.String name) throws java.io.IOException
getOption
in interface IConnection
name
- the name of the option
java.io.IOException
- In an I/O error occurspublic final java.util.Map<java.lang.String,java.lang.Class> getOptions()
getOptions
in interface IConnection
public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |