com.claritysys.io
Class MessageOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.FilterOutputStream
          extended by com.claritysys.io.MessageOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public final class MessageOutputStream
extends java.io.FilterOutputStream

A buffered output stream for encoding 2-byte-header message packets. Data is buffered internally in a byte array until the send () method is invoked. The data is then flushed to the underlying OutputStream with a 2 byte header with the message length in network byte order.

The internal buffer will grow to accomodate however much data is written to it.

Version:
$Revision: 2348 $ $Date: 2004-12-01 16:12:21 -0800 (Wed, 01 Dec 2004) $

Field Summary
protected  byte[] buffer
          The underlying buffer.
protected  int dataLength
          The length of data in the write buffer.
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
MessageOutputStream(java.io.OutputStream out)
          Construct a message stream on the given output stream.
 
Method Summary
 void flush()
          Send the message content on the underlying OutputStream.
 void write(byte[] b)
          Write the entire array b[] to the internal buffer.
 void write(byte[] b, int off, int len)
          Write an array of bytes to the internal buffer starting from off, length len.
 void write(int b)
          Write a single byte to the internal buffer.
 
Methods inherited from class java.io.FilterOutputStream
close
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

buffer

protected byte[] buffer
The underlying buffer.


dataLength

protected int dataLength
The length of data in the write buffer.

Constructor Detail

MessageOutputStream

public MessageOutputStream(java.io.OutputStream out)
Construct a message stream on the given output stream.

Parameters:
out - The underlying OutputStream to write to.
Method Detail

write

public void write(int b)
Write a single byte to the internal buffer. No data is sent until the send () method is invoked.

Overrides:
write in class java.io.FilterOutputStream
Parameters:
b - A byte to write.

write

public void write(byte[] b)
Write the entire array b[] to the internal buffer. No data is sent until the send () method is invoked.

Overrides:
write in class java.io.FilterOutputStream
Parameters:
b -

write

public void write(byte[] b,
                  int off,
                  int len)
Write an array of bytes to the internal buffer starting from off, length len. The data will not be sent until the send () method is invoked.

Overrides:
write in class java.io.FilterOutputStream
Parameters:
b -
off -
len -

flush

public void flush()
           throws java.io.IOException
Send the message content on the underlying OutputStream.

The data is sent with a 2 byte length header, high byte first. This is done with one write/flush to the underlying stream.

Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.FilterOutputStream
Throws:
java.io.IOException


Copyright ? 2002 Clarity Systems Group, LLC. All Rights Reserved.