condor.cedar
Class CedarOutputStream

Object
  extended byOutputStream
      extended byFilterOutputStream
          extended bycondor.cedar.CedarOutputStream
All Implemented Interfaces:
DataOutput

public class CedarOutputStream
extends FilterOutputStream
implements DataOutput

A Java output 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.11 $
Author:
Marvin solomon

Field Summary
static int DEFAULT_PACKET_SIZE
          The default maximum size of a packet (8192 bytes).
 
Fields inherited from class FilterOutputStream
out
 
Constructor Summary
CedarOutputStream(OutputStream out)
          Creates a new CedarOutputStream wrapping an exising stream.
CedarOutputStream(OutputStream out, int packetSize)
          Creates a new CedarOutputStream wrapping an exising stream with a given maximum packet size.
 
Method Summary
 void close()
          Flushs any buffered data, indicate end of message, and closes the underlying output stream.
 void endOfMessage()
          Sends an end of message indication, as a separate empty packet, if necessary.
 void flush()
          Sends the contents of the current output buffer as a packet.
 void write(byte[] b)
          Writes some data to the output.
 void write(byte[] b, int off, int len)
          Writes some data to the output.
 void write(int b)
          Writes one byte to the output.
 void writeBoolean(boolean v)
          Sends a boolean as a long integer (1 for true, 0 for false).
 void writeByte(int v)
          Sends a byte as is.
 void writeBytes(String v)
          Deprecated. Use writeUTF(java.lang.String) instead.
 void writeChar(int v)
          Sends a char as a long integer, zero-extended.
 void writeChars(String v)
          Deprecated. Use writeUTF(java.lang.String) instead.
 void writeDouble(double v)
          Sends a double, big endian (MSB first).
 void writeFloat(float v)
          Sends a float, big endian (MSB first).
 void writeInt(int v)
          Sends an integer as a long integer, sign-extended.
 void writeLong(long v)
          Sends a long integer, big endian (MSB first).
 void writeShort(int v)
          Sends a short as a long integer, sign-extended.
 void writeUTF(String v)
          Sends the string encoded using the Java version of UTF-8, followed by a null byte.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PACKET_SIZE

public static final int DEFAULT_PACKET_SIZE
The default maximum size of a packet (8192 bytes).

See Also:
Constant Field Values
Constructor Detail

CedarOutputStream

public CedarOutputStream(OutputStream out)
Creates a new CedarOutputStream wrapping an exising stream.

Parameters:
out - the destination for raw bytes.

CedarOutputStream

public CedarOutputStream(OutputStream out,
                         int packetSize)
Creates a new CedarOutputStream wrapping an exising stream with a given maximum packet size.

Parameters:
out - the destination for raw bytes.
packetSize - the maximum size of packet to send to stream "out".
Method Detail

write

public void write(int b)
           throws IOException
Writes one byte to the output.

Specified by:
write in interface DataOutput
Parameters:
b - the byte to write.
Throws:
IOException - if there is an I/O error on the underlying stream.

write

public void write(byte[] b)
           throws IOException
Writes some data to the output. Equivalent to write(b, 0, b.length).

Specified by:
write in interface DataOutput
Parameters:
b - the data to write.
Throws:
IOException - if there is an I/O error on the underlying stream.

write

public void write(byte[] b,
                  int off,
                  int len)
           throws IOException
Writes some data to the output.

Specified by:
write in interface DataOutput
Parameters:
b - the data to write.
off - the starting location in the buffer.
len - the number of bytes to write.
Throws:
IOException - if there is an I/O error on the underlying stream.

flush

public void flush()
           throws IOException
Sends the contents of the current output buffer as a packet. If the current output buffer is empty, no packet is sent.

Throws:
IOException - if there is an I/O error on the underlying stream.

close

public void close()
           throws IOException
Flushs any buffered data, indicate end of message, and closes the underlying output stream.

Throws:
IOException - if there is an I/O error on the underlying stream.

endOfMessage

public void endOfMessage()
                  throws IOException
Sends an end of message indication, as a separate empty packet, if necessary.

Throws:
IOException - if there is an I/O error on the underlying stream.

writeBoolean

public void writeBoolean(boolean v)
                  throws IOException
Sends a boolean as a long integer (1 for true, 0 for false).

Specified by:
writeBoolean in interface DataOutput
Parameters:
v - the data to send.
Throws:
IOException - if there is an I/O error on the underlying stream.

writeByte

public void writeByte(int v)
               throws IOException
Sends a byte as is.

Specified by:
writeByte in interface DataOutput
Parameters:
v - the data to send.
Throws:
IOException - if there is an I/O error on the underlying stream.

writeShort

public void writeShort(int v)
                throws IOException
Sends a short as a long integer, sign-extended.

Specified by:
writeShort in interface DataOutput
Parameters:
v - the data to send.
Throws:
IOException - if there is an I/O error on the underlying stream.

writeChar

public void writeChar(int v)
               throws IOException
Sends a char as a long integer, zero-extended.

Specified by:
writeChar in interface DataOutput
Parameters:
v - the data to send.
Throws:
IOException - if there is an I/O error on the underlying stream.

writeInt

public void writeInt(int v)
              throws IOException
Sends an integer as a long integer, sign-extended.

Specified by:
writeInt in interface DataOutput
Parameters:
v - the data to send.
Throws:
IOException - if there is an I/O error on the underlying stream.

writeLong

public void writeLong(long v)
               throws IOException
Sends a long integer, big endian (MSB first).

Specified by:
writeLong in interface DataOutput
Parameters:
v - the data to send.
Throws:
IOException - if there is an I/O error on the underlying stream.

writeFloat

public void writeFloat(float v)
                throws IOException
Sends a float, big endian (MSB first).

Specified by:
writeFloat in interface DataOutput
Parameters:
v - the data to send.
Throws:
IOException - if there is an I/O error on the underlying stream.

writeDouble

public void writeDouble(double v)
                 throws IOException
Sends a double, big endian (MSB first).

Specified by:
writeDouble in interface DataOutput
Parameters:
v - the data to send.
Throws:
IOException - if there is an I/O error on the underlying stream.

writeBytes

public void writeBytes(String v)
                throws IOException
Deprecated. Use writeUTF(java.lang.String) instead.

Sends the low order byte of each character in the string. Why isn't this deprecated?

Specified by:
writeBytes in interface DataOutput
Parameters:
v - the data to send.
Throws:
IOException - if there is an I/O error on the underlying stream.

writeChars

public void writeChars(String v)
                throws IOException
Deprecated. Use writeUTF(java.lang.String) instead.

Sends each character as two bytes, high byte first.

Specified by:
writeChars in interface DataOutput
Parameters:
v - the data to send.
Throws:
IOException - if there is an I/O error on the underlying stream.

writeUTF

public void writeUTF(String v)
              throws IOException
Sends the string encoded using the Java version of UTF-8, followed by a null byte. Note that the Java version of UTF-8 never produces a null byte.

Specified by:
writeUTF in interface DataOutput
Parameters:
v - the data to send.
Throws:
IOException - if there is an I/O error on the underlying stream.