condor.cedar
Class CedarInputStream

Object
  |
  +--InputStream
        |
        +--FilterInputStream
              |
              +--condor.cedar.CedarInputStream
All Implemented Interfaces:
DataInput

public class CedarInputStream
extends FilterInputStream
implements DataInput

A Java input stream that more-or-less corresponds to the C++ class ReliSock. Except for floats, this class attempts to be compatible with the existing Condor conventions for sending data over a connection. See The package description for details.

Version:
$Revision: 1.12 $
Author:
Marvin solomon

Field Summary
 
Fields inherited from class FilterInputStream
in
 
Constructor Summary
CedarInputStream(InputStream in)
          Creates a new CedarInputStream wrapping an exising stream.
 
Method Summary
 int available()
          Returns the number of bytes buffered.
 void close()
          Closes the underlying stream and discards all buffered data.
 int getByteCount()
          Returns the number of "raw" bytes consumed from the original input stream, including Cedar overhead, since this stream was opened.
 void mark(int n)
          Does nothing (mark not supported).
 boolean markSupported()
          Always returns false (mark not supported)
 boolean nextMessage()
          Advances the input stream to the start of the next message.
 int read()
          Reads one byte from the input stream.
 int read(byte[] b)
          Reads at most b.length bytes from the input stream.
 int read(byte[] b, int off, int len)
          Reads at most len bytes from the input stream into buffer b, starting at offset off.
 boolean readBoolean()
          Reads one boolean from the input stream.
 byte readByte()
          Reads a byte from the input stream.
 char readChar()
          Reads one character from the input stream.
 double readDouble()
          Reads a double from the input stream.
 float readFloat()
          Reads a float from the input stream.
 void readFully(byte[] b)
          Equivalent to readFully(b, 0, b.length).
 void readFully(byte[] b, int off, int len)
          Reads a specified number of bytes, or throws an exception if there are not that many more bytes before the next end-of-message indication.
 int readInt()
          Reads an integer from the input stream.
 String readLine()
          Deprecated. Use readUTF() instead.
 long readLong()
          Reads a long (64-bit) integer from the input stream.
 short readShort()
          Reads a short from the input stream.
 int readUnsignedByte()
          Reads an unsigned byte from the input stream.
 int readUnsignedShort()
          Reads an unsigned short from the input stream.
 String readUTF()
          Reads a null-terminated string in modified UTF-8 encoding from the input and throw away the terminating null.
 int readUTFchar()
          Reads one character in UTF format from the input.
 void reset()
          Always throws IOException (mark not supported).
 long skip(long n)
          Skips up n bytes or to the end of the current message, whichever comes first.
 int skipBytes(int n)
          Equivalent to (int) skip(n)
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CedarInputStream

public CedarInputStream(InputStream in)
Creates a new CedarInputStream wrapping an exising stream.

Parameters:
in - the source of raw bytes.
Method Detail

nextMessage

public boolean nextMessage()
                    throws IOException
Advances the input stream to the start of the next message. If the stream is already in the last message, the buffer is left looking as if the stream is positioned inside a zero-length message. Note that this is the only method of this class that will read beyond the end of the current message.

Returns:
false if the stream is positioned inside the last message of input at the point of call.
Throws:
IOExecption - if there is an I/O error on the underlying stream.
IOException

read

public int read()
         throws IOException
Reads one byte from the input stream.

Overrides:
read in class FilterInputStream
Returns:
the next input byte, or -1 if the stream is positioned at end-of-message.
Throws:
IOExecption - if there is an I/O error on the underlying stream.
IOException

read

public int read(byte[] b)
         throws IOException
Reads at most b.length bytes from the input stream.

Overrides:
read in class FilterInputStream
Parameters:
b - the place to put the data.
Returns:
the number of bytes read. Returns -1 if the stream is at end-of-message. Never returns 0.
Throws:
IOExecption - if there is an I/O error on the underlying stream.
IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Reads at most len bytes from the input stream into buffer b, starting at offset off.

Overrides:
read in class FilterInputStream
Parameters:
b - the place to put the data.
off - starting offset in b.
len - maximum number of bytes to read.
Returns:
the number of bytes read. Returns -1 if the stream is at end-of-message. Never returns 0.
Throws:
IOExecption - if there is an I/O error on the underlying stream.
IOException

skip

public long skip(long n)
          throws IOException
Skips up n bytes or to the end of the current message, whichever comes first.

Overrides:
skip in class FilterInputStream
Parameters:
n - the maximum number of bytes to skip.
Returns:
the number of bytes skipped.
Throws:
IOExecption - if there is an I/O error on the underlying stream.
IOException

available

public int available()
              throws IOException
Returns the number of bytes buffered. If no data is currently buffered, first read until there is some data buffered, or end-of-message is encountered, whichever comes first.

Overrides:
available in class FilterInputStream
Returns:
the number of bytes buffered, perhaps after first refilling the buffer.
Throws:
IOExecption - if there is an I/O error on the underlying stream.
IOException

close

public void close()
           throws IOException
Closes the underlying stream and discards all buffered data.

Overrides:
close in class FilterInputStream
Throws:
IOExecption - if there is an I/O error on the underlying stream.
IOException

mark

public void mark(int n)
Does nothing (mark not supported).

Overrides:
mark in class FilterInputStream

reset

public void reset()
           throws IOException
Always throws IOException (mark not supported).

Overrides:
reset in class FilterInputStream
Throws:
IOException - always.

markSupported

public boolean markSupported()
Always returns false (mark not supported)

Overrides:
markSupported in class FilterInputStream

readFully

public void readFully(byte[] b)
               throws IOException
Equivalent to readFully(b, 0, b.length).

Specified by:
readFully in interface DataInput
Parameters:
b - a place to put the data.
IOException

readFully

public void readFully(byte[] b,
                      int off,
                      int len)
               throws IOException
Reads a specified number of bytes, or throws an exception if there are not that many more bytes before the next end-of-message indication.

Specified by:
readFully in interface DataInput
Parameters:
b - place to put the data.
off - offset within b where the data starts.
len - number of bytes to read.
Throws:
EOFException - if end-of-message is encountered before the specified number of bytes are read.
IOExecption - if there is an I/O error on the underlying stream.
IOException

skipBytes

public int skipBytes(int n)
              throws IOException
Equivalent to (int) skip(n)

Specified by:
skipBytes in interface DataInput
Parameters:
n - the maximum number of bytes to skip.
Returns:
the number of bytes skipped.
Throws:
IOExecption - if there is an I/O error on the underlying stream.
IOException

readBoolean

public boolean readBoolean()
                    throws IOException
Reads one boolean from the input stream.

Specified by:
readBoolean in interface DataInput
Returns:
the value read.
Throws:
IOExecption - if there is an I/O error on the underlying stream.
IOException

readByte

public byte readByte()
              throws IOException
Reads a byte from the input stream.

Specified by:
readByte in interface DataInput
Returns:
the value read.
Throws:
IOExecption - if there is an I/O error on the underlying stream.
IOException

readUnsignedByte

public int readUnsignedByte()
                     throws IOException
Reads an unsigned byte from the input stream.

Specified by:
readUnsignedByte in interface DataInput
Returns:
the value read.
Throws:
IOExecption - if there is an I/O error on the underlying stream.
IOException

readShort

public short readShort()
                throws IOException
Reads a short from the input stream.

Specified by:
readShort in interface DataInput
Returns:
the value read.
Throws:
IOExecption - if there is an I/O error on the underlying stream.
IOException

readUnsignedShort

public int readUnsignedShort()
                      throws IOException
Reads an unsigned short from the input stream.

Specified by:
readUnsignedShort in interface DataInput
Returns:
the value read.
Throws:
IOExecption - if there is an I/O error on the underlying stream.
IOException

readChar

public char readChar()
              throws IOException
Reads one character from the input stream.

Specified by:
readChar in interface DataInput
Returns:
the value read.
Throws:
IOExecption - if there is an I/O error on the underlying stream.
IOException

readInt

public int readInt()
            throws IOException
Reads an integer from the input stream.

Specified by:
readInt in interface DataInput
Returns:
the value read.
Throws:
IOExecption - if there is an I/O error on the underlying stream.
IOException

readLong

public long readLong()
              throws IOException
Reads a long (64-bit) integer from the input stream.

Specified by:
readLong in interface DataInput
Returns:
the value read.
Throws:
IOExecption - if there is an I/O error on the underlying stream.
IOException

readFloat

public float readFloat()
                throws IOException
Reads a float from the input stream.

Specified by:
readFloat in interface DataInput
Returns:
the value read.
Throws:
IOExecption - if there is an I/O error on the underlying stream.
IOException

readDouble

public double readDouble()
                  throws IOException
Reads a double from the input stream.

Specified by:
readDouble in interface DataInput
Returns:
the value read.
Throws:
IOExecption - if there is an I/O error on the underlying stream.
IOException

readLine

public String readLine()
                throws IOException
Deprecated. Use readUTF() instead.

Reads bytes, converting them to characters, until end-of-line or end-of-message is seen. See DataInput.readLine() for details. It is not clear to me why this ridiculous thing is not deprecated.

Specified by:
readLine in interface DataInput
Returns:
a string composed of the characters read.
Throws:
IOExecption - if there is an I/O error on the underlying stream.
IOException

readUTF

public String readUTF()
               throws IOException
Reads a null-terminated string in modified UTF-8 encoding from the input and throw away the terminating null.

Specified by:
readUTF in interface DataInput
Returns:
the value read.
Throws:
UTFDataFormatException - if the input data contains a bad escape sequece.
EOFException - if end-of-message is encountered before a null.
IOExecption - if there is an I/O error on the underlying stream.
IOException

readUTFchar

public final int readUTFchar()
                      throws IOException
Reads one character in UTF format from the input.

Returns:
the character read, or -1 if a null is encountered in the input stream (note that a null in the input stream cannot be part of the UTF encoding of any character).
Throws:
UTFDataFormatException - if the input data contains a bad escape sequece.
EOFException - if end-of-message is encountered.
IOExecption - if there is an I/O error on the underlying stream.
IOException

getByteCount

public int getByteCount()
Returns the number of "raw" bytes consumed from the original input stream, including Cedar overhead, since this stream was opened.

Returns:
the number of bytes read.