edu.sdsc.inca.protocol
Class ProtocolReader

java.lang.Object
  extended by java.io.Reader
      extended by java.io.BufferedReader
          extended by edu.sdsc.inca.protocol.ProtocolReader
All Implemented Interfaces:
java.io.Closeable, java.lang.Readable

public class ProtocolReader
extends java.io.BufferedReader

Author:
Cathie Olschanowsky, Jim Hayes Used for efficiently handling the input streams that hold inca protocol bytes.

To use it

reader = new ProtocolReader(new InputStreamReader(inputStream)); reader.peekCommand reader.getStatement ...


Field Summary
protected  boolean closed
           
static int CR
           
static int LF
           
protected static org.apache.log4j.Logger logger
           
static int MAX_COMMAND_LENGTH
           
static int SP
           
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
ProtocolReader(java.io.InputStream input)
          Create a buffering protocol-input stream that uses a default-sized input buffer.
ProtocolReader(java.io.InputStream input, int i)
          Create a buffering character-input stream that uses an input buffer of the specified size.
ProtocolReader(java.io.Reader reader)
          Create a buffering protocol-input stream that uses a default-sized input buffer.
ProtocolReader(java.io.Reader reader, int i)
          Create a buffering character-input stream that uses an input buffer of the specified size.
 
Method Summary
 void close()
          Closes the reader.
 boolean isClosed()
          Indicates whether or not the reader has been closed.
 java.lang.String peekCommand()
          Returns the next command from the stream, or null on end.
 Statement readStatement()
          Reads a complete statement from the input stream, or null if the stream has been closed.
 java.lang.String readStatement(java.io.Writer outStream)
          Reads a complete statement from the input stream, or null if the stream has been closed.
 
Methods inherited from class java.io.BufferedReader
mark, markSupported, read, read, readLine, ready, reset, skip
 
Methods inherited from class java.io.Reader
read, read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_COMMAND_LENGTH

public static final int MAX_COMMAND_LENGTH
See Also:
Constant Field Values

CR

public static final int CR
See Also:
Constant Field Values

LF

public static final int LF
See Also:
Constant Field Values

SP

public static final int SP
See Also:
Constant Field Values

logger

protected static org.apache.log4j.Logger logger

closed

protected boolean closed
Constructor Detail

ProtocolReader

public ProtocolReader(java.io.Reader reader,
                      int i)
Create a buffering character-input stream that uses an input buffer of the specified size.

Parameters:
reader - the reader that the data can be read from
i - size of the input buffer

ProtocolReader

public ProtocolReader(java.io.Reader reader)
Create a buffering protocol-input stream that uses a default-sized input buffer.

Parameters:
reader - the reader that the protocol can be read from

ProtocolReader

public ProtocolReader(java.io.InputStream input,
                      int i)
Create a buffering character-input stream that uses an input buffer of the specified size.

Parameters:
input - the stream that the data can be read from
i - size of the input buffer

ProtocolReader

public ProtocolReader(java.io.InputStream input)
Create a buffering protocol-input stream that uses a default-sized input buffer.

Parameters:
input - the stream that the protocol can be read from
Method Detail

close

public void close()
           throws java.io.IOException
Closes the reader.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.BufferedReader
Throws:
java.io.IOException - on a close error

isClosed

public boolean isClosed()
Indicates whether or not the reader has been closed.

Returns:
true if the reader is closed, else false

peekCommand

public java.lang.String peekCommand()
                             throws java.io.IOException,
                                    ProtocolException
Returns the next command from the stream, or null on end. The command will be re-read by the next call to readStatement.

Returns:
the next command
Throws:
java.io.IOException - on a read error
ProtocolException - if the contents of the read are malformed

readStatement

public Statement readStatement()
                        throws java.io.IOException,
                               ProtocolException
Reads a complete statement from the input stream, or null if the stream has been closed.

Returns:
the next statement -- complete
Throws:
java.io.IOException - on a read error
ProtocolException - if the contents of the read are malformed

readStatement

public java.lang.String readStatement(java.io.Writer outStream)
                               throws java.io.IOException,
                                      ProtocolException
Reads a complete statement from the input stream, or null if the stream has been closed. The data portion of the statement is written to the given output stream.

Parameters:
outStream - a stream to write the statement data to
Returns:
the command
Throws:
java.io.IOException - on a read error
ProtocolException - if the contents of the read are malformed