org.pf.net
Class TextSocketConnection

java.lang.Object
  extended by org.pf.util.ExceptionIgnorer
      extended by org.pf.net.SocketConnection
          extended by org.pf.net.TextSocketConnection

public class TextSocketConnection
extends SocketConnection

A connection based on a opened socket. The connection provides convenient methods to read and write lines from/to the underlying socket.

Version:
1.1
Author:
Manfred Duchrow

Constructor Summary
TextSocketConnection(java.net.Socket openSocket)
          Initialize the new instance to work on the given socket.
TextSocketConnection(java.net.Socket openSocket, ExceptionHandler exHandler)
          Initialize the new instance to work on the given socket and use the specified exception handler to report exceptions to.
 
Method Summary
 void close()
          Close the connection and all release underlying resources.
 java.lang.String readLine()
          Reads the next line from the socket's input stream and returns it.
 boolean write(java.lang.String text)
          Writes the given text to the socket's output stream.
 boolean writeLine(java.lang.String line)
          Writes the given string to the socket's output stream and appends a newline character.
 
Methods inherited from class org.pf.net.SocketConnection
isClosed, isOpen
 
Methods inherited from class org.pf.util.ExceptionIgnorer
exceptionOccurred, getExceptionHandler, setExceptionHandler
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextSocketConnection

public TextSocketConnection(java.net.Socket openSocket)
Initialize the new instance to work on the given socket.


TextSocketConnection

public TextSocketConnection(java.net.Socket openSocket,
                            ExceptionHandler exHandler)
Initialize the new instance to work on the given socket and use the specified exception handler to report exceptions to.

Method Detail

close

public void close()
Close the connection and all release underlying resources.

Overrides:
close in class SocketConnection

readLine

public java.lang.String readLine()
Reads the next line from the socket's input stream and returns it. Returns null in case of any error or if no more data is available.


write

public boolean write(java.lang.String text)
Writes the given text to the socket's output stream. Returns true, if everything went well, otherwise false.


writeLine

public boolean writeLine(java.lang.String line)
Writes the given string to the socket's output stream and appends a newline character. Returns true, if everything went well, otherwise false.