infoservice.mailsystem.central.server.util
Class SocketContainer

java.lang.Object
  extended by infoservice.mailsystem.central.server.util.SocketContainer

public class SocketContainer
extends java.lang.Object

This class enables usage of alternative input and output streams for a socket.


Field Summary
private  java.io.InputStream m_alternativeInputStream
          Stores an alternative input stream.
private  java.io.OutputStream m_alternativeOutputStream
          Stores an alternative output stream.
private  java.net.Socket m_socket
          Stores the origin socket.
 
Constructor Summary
SocketContainer(java.net.Socket a_socket, java.io.InputStream a_alternativeInputStream, java.io.OutputStream a_alternativeOutputStream)
          Creates a new instance of SocketContainer.
 
Method Summary
 void close()
          Closes the socket, see Socket.close().
 SocketContainer createChildContainer(java.io.InputStream a_alternativeInputStream, java.io.OutputStream a_alternativeOutputStream)
          Creates a child of this SocketContainer.
 java.io.InputStream getInputStream()
          Returns the InputStream to use.
 java.io.OutputStream getOutputStream()
          Returns the OutputStream to use.
 void setSocketTimeout(int a_timeout)
          Changes the timeout for the underlying socket.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_socket

private java.net.Socket m_socket
Stores the origin socket.


m_alternativeInputStream

private java.io.InputStream m_alternativeInputStream
Stores an alternative input stream. So read requests can be detoured to this stream. If this value is null, the origin input stream of the socket is used.


m_alternativeOutputStream

private java.io.OutputStream m_alternativeOutputStream
Stores an alternative output stream. So write requests can be detoured to this stream. If this value is null, the origin output stream of the socket is used.

Constructor Detail

SocketContainer

public SocketContainer(java.net.Socket a_socket,
                       java.io.InputStream a_alternativeInputStream,
                       java.io.OutputStream a_alternativeOutputStream)
Creates a new instance of SocketContainer.

Parameters:
a_socket - The underlying socket to use.
a_alternativeInputStream - Specifies an alternative InputStream the SocketContainer shall use. If null is specified, it will use the InputStream of the socket itself.
a_alternativeOutputStream - Specifies an alternative OutputStream the SocketContainer shall use. If null is specified, it will use the OutputStream of the socket itself.
Method Detail

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Returns the InputStream to use. If an alternative InputStream was specified in the constructor, that stream is returned. If no alternative InputStream was specified, the origin stream of the socket is used.

Returns:
The InputStream to use for reading data.
Throws:
java.io.IOException

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws java.io.IOException
Returns the OutputStream to use. If an alternative OutputStream was specified in the constructor, that stream is returned. If no alternative OutputStream was specified, the origin stream of the socket is used.

Returns:
The OutputStream to use for writing data.
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Closes the socket, see Socket.close().

Throws:
java.io.IOException

setSocketTimeout

public void setSocketTimeout(int a_timeout)
                      throws java.net.SocketException
Changes the timeout for the underlying socket. See Socket.setSoTimeout().

Parameters:
a_timeout - The timeout for the socket in ms. If 0 is specified, no timeout is used.
Throws:
java.net.SocketException

createChildContainer

public SocketContainer createChildContainer(java.io.InputStream a_alternativeInputStream,
                                            java.io.OutputStream a_alternativeOutputStream)
                                     throws java.io.IOException
Creates a child of this SocketContainer. The child uses the same socket and as default also the same input and output streams as this container (unless something else is specified).

Parameters:
a_alternativeInputStream - Specifies an alternative InputStream the child shall use. If null is specified, it will use the InputStream returned by getInputStream().
a_alternativeOutputStream - Specifies an alternative OutputStream the child shall use. If null is specified, it will use the OutputStream returned by getOutputStream().
Returns:
The SocketContainer using the same underlying socket and the specified input and output streams.
Throws:
java.io.IOException