fr.dyade.aaa.agent
Class MessageOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by fr.dyade.aaa.agent.MessageOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable
Direct Known Subclasses:
BufferedMessageOutputStream, ByteArrayMessageOutputStream, UDPNetwork.DatagramOutputStream

public abstract class MessageOutputStream
extends java.io.OutputStream

Class used to send messages through a stream.

This OutputStream is a combination between a ByteArrayOutputStream and a BufferedOutputStream. It allows the replacement of the underlying stream and the serialization of object through an internal ObjectOutputStream.

Be careful this OutputStream is not synchronized.


Field Summary
protected  byte[] buf
          The internal buffer where data is stored.
protected  boolean compressedFlows
           
protected  int count
          The number of valid bytes in the buffer.
protected static org.objectweb.util.monolog.api.Logger logmon
          Default logger for MessageOutputStream.
protected  java.io.ObjectOutputStream oos
          The internal ObjectOutputStream needed to serialize the notification.
private static byte STREAM_MAGIC1
           
private static byte STREAM_MAGIC2
           
private static byte STREAM_VERSION1
           
private static byte STREAM_VERSION2
           
 
Constructor Summary
MessageOutputStream()
          Creates a new output stream to write data to an unspecified underlying output stream through a buffer with default size.
MessageOutputStream(int size)
          Creates a new output stream to write data to an unspecified underlying output stream through a buffer with specified size.
 
Method Summary
protected static org.objectweb.util.monolog.api.Logger getLogger()
          Returns default logger for MessageOutputStream.
 void write(byte[] b)
          Writes b.length bytes to this output stream.
abstract  void write(byte[] b, int off, int len)
          Writes len bytes from the specified byte array starting at offset off to this output stream.
abstract  void write(int b)
          Writes the specified byte to this output stream.
protected abstract  void writeHeader()
          Writes the protocol header to this output stream.
protected  void writeInt(int i)
          Writes an int directly to the buffer.
protected  void writeMessage(Message msg, long time)
          Writes a message to this output stream.
protected  void writeMessageHeader(Message msg)
          Writes the message header data to the buffer.
protected  void writeShort(short s)
          Writes a short directly to the buffer.
 
Methods inherited from class java.io.OutputStream
close, flush
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

oos

protected java.io.ObjectOutputStream oos
The internal ObjectOutputStream needed to serialize the notification.


buf

protected byte[] buf
The internal buffer where data is stored.


count

protected int count
The number of valid bytes in the buffer.


compressedFlows

protected boolean compressedFlows

logmon

protected static org.objectweb.util.monolog.api.Logger logmon
Default logger for MessageOutputStream.


STREAM_MAGIC1

private static final byte STREAM_MAGIC1
See Also:
Constant Field Values

STREAM_MAGIC2

private static final byte STREAM_MAGIC2
See Also:
Constant Field Values

STREAM_VERSION1

private static final byte STREAM_VERSION1
See Also:
Constant Field Values

STREAM_VERSION2

private static final byte STREAM_VERSION2
See Also:
Constant Field Values
Constructor Detail

MessageOutputStream

public MessageOutputStream()
                    throws java.io.IOException
Creates a new output stream to write data to an unspecified underlying output stream through a buffer with default size.

Throws:
java.io.IOException

MessageOutputStream

public MessageOutputStream(int size)
                    throws java.io.IOException
Creates a new output stream to write data to an unspecified underlying output stream through a buffer with specified size.

Parameters:
size - the buffer size.
Throws:
java.lang.IllegalArgumentException - if size is less than 0.
java.io.IOException - if the internal ObjectOutputStream cannot be correctly initialized.
Method Detail

getLogger

protected static org.objectweb.util.monolog.api.Logger getLogger()
Returns default logger for MessageOutputStream.

Returns:
Default logger for MessageOutputStream.

write

public abstract void write(int b)
                    throws java.io.IOException
Writes the specified byte to this output stream.

Specified by:
write in class java.io.OutputStream
Parameters:
b - the byte to be written.
Throws:
java.io.IOException - if an I/O error occurs.

write

public final void write(byte[] b)
                 throws java.io.IOException
Writes b.length bytes to this output stream.

This method calls its write method of three arguments with the arguments b, 0, and b.length.

Overrides:
write in class java.io.OutputStream
Parameters:
b - the data to be written.
Throws:
java.io.IOException - if an I/O error occurs.
See Also:
write(byte[], int, int)

write

public abstract void write(byte[] b,
                           int off,
                           int len)
                    throws java.io.IOException
Writes len bytes from the specified byte array starting at offset off to this output stream.

Overrides:
write in class java.io.OutputStream
Parameters:
b - the data.
off - the start offset in the data.
len - the number of bytes to write.
Throws:
java.io.IOException - if an I/O error occurs.

writeShort

protected final void writeShort(short s)
Writes a short directly to the buffer. Be careful, the buffer must be large enough to contain the short.

Parameters:
s - the data.

writeInt

protected final void writeInt(int i)
Writes an int directly to the buffer. Be careful, the buffer must be large enough to contain the int.

Parameters:
i - the data.

writeHeader

protected abstract void writeHeader()
                             throws java.io.IOException
Writes the protocol header to this output stream. This method must be overloaded in subclass.

Throws:
java.io.IOException

writeMessageHeader

protected final void writeMessageHeader(Message msg)
Writes the message header data to the buffer.

Parameters:
msg - The message to write out.

writeMessage

protected final void writeMessage(Message msg,
                                  long time)
                           throws java.io.IOException
Writes a message to this output stream. This method can be overloaded in subclass.

Parameters:
msg - The message to write out.
time - The current time in milliseconds, this parameter is used to the handling of notification expiration.
Throws:
java.io.IOException


Copyright © 2010 ScalAgent D.T.. All Rights Reserved.