de.cau.cs.kieler.krep.evalbench.comm
Class Connection

java.lang.Object
  extended by de.cau.cs.kieler.krep.evalbench.comm.Connection
All Implemented Interfaces:
IConnection
Direct Known Subclasses:
RxtxSerialConnection, SocketConnection

public abstract class Connection
extends Object
implements IConnection

Abstract superclass for connection protocols that use input and output streams.

Rating yellow
(2010-02-05) review by cmot, msp

Constructor Summary
Connection()
           
 
Method Summary
protected abstract  InputStreamReader getInput()
          Retrieves the input stream for this connection.
protected abstract  OutputStream getOutput()
          Retrieves the output stream for this connection.
 String hark(int n)
          Harks to incoming data.
 String receive(char exit)
          Tries to receive a sequence of characters until an exit character is read.
 String receive(int n)
          Tries to receive a fixed number of characters.
 LinkedList<Integer> receiveByte(int n)
          Tries to receive a fixed number of characters.
 void send(byte data)
          Sends data to the target.
 void send(byte[] data)
          Sends data to the target.
 void send(String data)
          Sends data to the target.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.cau.cs.kieler.krep.evalbench.comm.IConnection
dispose
 

Constructor Detail

Connection

public Connection()
Method Detail

getInput

protected abstract InputStreamReader getInput()
Retrieves the input stream for this connection.

Returns:
the input stream, or null if no input stream is available

getOutput

protected abstract OutputStream getOutput()
Retrieves the output stream for this connection.

Returns:
the output stream, or null if no output stream is available

receive

public String receive(char exit)
               throws CommunicationException
Tries to receive a sequence of characters until an exit character is read. The exit character is included in the returned string.

Specified by:
receive in interface IConnection
Parameters:
exit - the exit character
Returns:
received data
Throws:
CommunicationException - when a timeout is reached before the exit character is read

receive

public String receive(int n)
               throws CommunicationException
Tries to receive a fixed number of characters.

Specified by:
receive in interface IConnection
Parameters:
n - the number of characters to be fetched
Returns:
received data
Throws:
CommunicationException - when a timeout is reached before the exit character is read

receiveByte

public LinkedList<Integer> receiveByte(int n)
                                throws CommunicationException
Tries to receive a fixed number of characters.

Specified by:
receiveByte in interface IConnection
Parameters:
n - the number of characters to be fetched
Returns:
received data
Throws:
CommunicationException - when a timeout is reached before the exit character is read

hark

public String hark(int n)
            throws CommunicationException
Harks to incoming data.

Specified by:
hark in interface IConnection
Parameters:
n - maximal number of characters to receive
Returns:
characters received in a specific time range
Throws:
CommunicationException - when an exception occurs while receiving data

send

public void send(String data)
          throws CommunicationException
Sends data to the target.

Specified by:
send in interface IConnection
Parameters:
data - data to be sent
Throws:
CommunicationException - when an exception occurs while sending data

send

public void send(byte data)
          throws CommunicationException
Sends data to the target.

Specified by:
send in interface IConnection
Parameters:
data - data to be sent
Throws:
CommunicationException - when an exception occurs while sending data

send

public void send(byte[] data)
          throws CommunicationException
Sends data to the target.

Specified by:
send in interface IConnection
Parameters:
data - data to be sent
Throws:
CommunicationException - when an exception occurs while sending data