org.springframework.integration.ip.tcp
Class NetSocketReader

java.lang.Object
  extended by org.springframework.integration.ip.tcp.AbstractSocketReader
      extended by org.springframework.integration.ip.tcp.NetSocketReader
All Implemented Interfaces:
MessageFormats, SocketReader

public class NetSocketReader
extends AbstractSocketReader

A SocketReader that reads from a Socket. Threads calling AbstractSocketReader.assembledData will block until a message is completely assembled.

Author:
Gary Russell

Field Summary
protected  org.apache.commons.logging.Log logger
           
protected  int receiveBufferSize
           
protected  java.net.Socket socket
           
 
Fields inherited from class org.springframework.integration.ip.tcp.AbstractSocketReader
assembledData, messageFormat
 
Fields inherited from interface org.springframework.integration.ip.tcp.MessageFormats
ETX, FORMAT_CRLF, FORMAT_CUSTOM, FORMAT_LENGTH_HEADER, FORMAT_STX_ETX, STX
 
Constructor Summary
NetSocketReader(java.net.Socket socket)
          Constructs a NetsocketReader which reads from the Socket.
 
Method Summary
protected  boolean assembleDataCrLfFormat()
          Assembles data in format MessageFormats.FORMAT_CRLF.
protected  boolean assembleDataCustomFormat()
          Throws UnsupportedOperationException; custom implementations can subclass this class and provide an implementation for this method.
protected  boolean assembleDataLengthFormat()
          Assembles data in format MessageFormats.FORMAT_LENGTH_HEADER.
protected  boolean assembleDataStxEtxFormat()
          Assembles data in format MessageFormats.FORMAT_STX_ETX.
protected  void doClose()
          Called after an exception; close the transport.
 java.net.InetAddress getAddress()
          Returns the InetAddress of the underlying socket.
 byte[] getAssembledData()
          Retrieves the assembled tcp data or null if the data is not yet assembled.
protected  void read(byte[] buffer)
          Reads data from the socket and puts the data in buffer.
 
Methods inherited from class org.springframework.integration.ip.tcp.AbstractSocketReader
assembleData, setMessageFormat
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final org.apache.commons.logging.Log logger

socket

protected java.net.Socket socket

receiveBufferSize

protected int receiveBufferSize
Constructor Detail

NetSocketReader

public NetSocketReader(java.net.Socket socket)
Constructs a NetsocketReader which reads from the Socket.

Parameters:
socket - The socket.
Method Detail

assembleDataLengthFormat

protected boolean assembleDataLengthFormat()
                                    throws java.io.IOException
Description copied from class: AbstractSocketReader
Assembles data in format MessageFormats.FORMAT_LENGTH_HEADER.

Specified by:
assembleDataLengthFormat in class AbstractSocketReader
Returns:
True when a message is completely assembled.
Throws:
java.io.IOException

assembleDataStxEtxFormat

protected boolean assembleDataStxEtxFormat()
                                    throws java.io.IOException
Description copied from class: AbstractSocketReader
Assembles data in format MessageFormats.FORMAT_STX_ETX.

Specified by:
assembleDataStxEtxFormat in class AbstractSocketReader
Returns:
True when a message is completely assembled.
Throws:
java.io.IOException

assembleDataCrLfFormat

protected boolean assembleDataCrLfFormat()
                                  throws java.io.IOException
Description copied from class: AbstractSocketReader
Assembles data in format MessageFormats.FORMAT_CRLF.

Specified by:
assembleDataCrLfFormat in class AbstractSocketReader
Returns:
True when a message is completely assembled.
Throws:
java.io.IOException

assembleDataCustomFormat

protected boolean assembleDataCustomFormat()
                                    throws java.io.IOException
Throws UnsupportedOperationException; custom implementations can subclass this class and provide an implementation for this method.

Specified by:
assembleDataCustomFormat in class AbstractSocketReader
Returns:
True when a message is completely assembled.
Throws:
java.io.IOException
See Also:
AbstractSocketReader.assembleDataCustomFormat().

getAssembledData

public byte[] getAssembledData()
Description copied from interface: SocketReader
Retrieves the assembled tcp data or null if the data is not yet assembled. Once this method is called, the assembled data is again null until a new assembly is completed.

Returns:
The assembled data or null.

read

protected void read(byte[] buffer)
             throws java.io.IOException
Reads data from the socket and puts the data in buffer. Blocks until buffer is full or a socket timeout occurs.

Parameters:
buffer -
Throws:
java.io.IOException

doClose

protected void doClose()
Description copied from class: AbstractSocketReader
Called after an exception; close the transport.

Specified by:
doClose in class AbstractSocketReader

getAddress

public java.net.InetAddress getAddress()
Description copied from interface: SocketReader
Returns the InetAddress of the underlying socket.

Returns:
The InetAddress.