net.sf.asterisk.io.impl
Class SocketConnectionFacadeImpl

java.lang.Object
  extended by net.sf.asterisk.io.impl.SocketConnectionFacadeImpl
All Implemented Interfaces:
SocketConnectionFacade

public class SocketConnectionFacadeImpl
extends java.lang.Object
implements SocketConnectionFacade

Default implementation of the SocketConnectionFacade interface using java.io.

Version:
$Id: SocketConnectionFacadeImpl.java,v 1.1 2005/10/25 22:43:25 srt Exp $
Author:
srt

Constructor Summary
SocketConnectionFacadeImpl(java.lang.String host, int port)
           
SocketConnectionFacadeImpl(java.lang.String host, int port, int timeout)
           
 
Method Summary
 void close()
          Closes the socket connection including its input and output stream and frees all associated ressources.
When calling close() any Thread currently blocked by a call to readLine() will be unblocked and receive an IOException.
 void flush()
          Flushes the socket connection, that is sends any buffered but yet unsent data.
 java.net.InetAddress getLocalAddress()
          Returns the local address this socket connection.
 int getLocalPort()
          Returns the local port of this socket connection.
 java.net.InetAddress getRemoteAddress()
          Returns the remote address of this socket connection.
 int getRemotePort()
          Returns the remote port of this socket connection.
 boolean isConnected()
          Returns the connection state of the socket.
 java.lang.String readLine()
          Reads a line of text from the socket connection.
 void write(java.lang.String s)
          Sends a given String to the socket connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SocketConnectionFacadeImpl

public SocketConnectionFacadeImpl(java.lang.String host,
                                  int port)
                           throws java.io.IOException
Throws:
java.io.IOException

SocketConnectionFacadeImpl

public SocketConnectionFacadeImpl(java.lang.String host,
                                  int port,
                                  int timeout)
                           throws java.io.IOException
Throws:
java.io.IOException
Method Detail

readLine

public java.lang.String readLine()
                          throws java.io.IOException
Description copied from interface: SocketConnectionFacade
Reads a line of text from the socket connection. The current thread is blocked until either the next line is received or an IOException encounters.

Specified by:
readLine in interface SocketConnectionFacade
Returns:
the line of text received excluding any newline character
Throws:
java.io.IOException - if the connection has been closed.

write

public void write(java.lang.String s)
           throws java.io.IOException
Description copied from interface: SocketConnectionFacade
Sends a given String to the socket connection.

Specified by:
write in interface SocketConnectionFacade
Parameters:
s - the String to send.
Throws:
java.io.IOException - if the String cannot be sent, maybe because the connection has already been closed.

flush

public void flush()
           throws java.io.IOException
Description copied from interface: SocketConnectionFacade
Flushes the socket connection, that is sends any buffered but yet unsent data.

Specified by:
flush in interface SocketConnectionFacade
Throws:
java.io.IOException - if the connection cannot be flushed.

close

public void close()
           throws java.io.IOException
Description copied from interface: SocketConnectionFacade
Closes the socket connection including its input and output stream and frees all associated ressources.
When calling close() any Thread currently blocked by a call to readLine() will be unblocked and receive an IOException.

Specified by:
close in interface SocketConnectionFacade
Throws:
java.io.IOException - if the socket connection cannot be closed.

isConnected

public boolean isConnected()
Description copied from interface: SocketConnectionFacade
Returns the connection state of the socket.

Specified by:
isConnected in interface SocketConnectionFacade
Returns:
true if the socket successfuly connected to a server

getLocalAddress

public java.net.InetAddress getLocalAddress()
Description copied from interface: SocketConnectionFacade
Returns the local address this socket connection.

Specified by:
getLocalAddress in interface SocketConnectionFacade
Returns:
the local address this socket connection.

getLocalPort

public int getLocalPort()
Description copied from interface: SocketConnectionFacade
Returns the local port of this socket connection.

Specified by:
getLocalPort in interface SocketConnectionFacade
Returns:
the local port of this socket connection.

getRemoteAddress

public java.net.InetAddress getRemoteAddress()
Description copied from interface: SocketConnectionFacade
Returns the remote address of this socket connection.

Specified by:
getRemoteAddress in interface SocketConnectionFacade
Returns:
the remote address of this socket connection.

getRemotePort

public int getRemotePort()
Description copied from interface: SocketConnectionFacade
Returns the remote port of this socket connection.

Specified by:
getRemotePort in interface SocketConnectionFacade
Returns:
the remote port of this socket connection.


Copyright © 2004-2005 Stefan Reuter. All Rights Reserved.