fr.dyade.aaa.agent
Class BufferedMessageOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by fr.dyade.aaa.agent.MessageOutputStream
          extended by fr.dyade.aaa.agent.BufferedMessageOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public abstract class BufferedMessageOutputStream
extends MessageOutputStream

Class used to send messages through a stream using buffering.

This OutputStream allows the replacement of the underlying stream and the serialisation of object through an internal ObjectOutputStream.

Be careful this OutputStream is not synchronized.


Field Summary
protected  java.io.OutputStream out
          The underlying output stream.
 
Fields inherited from class fr.dyade.aaa.agent.MessageOutputStream
buf, compressedFlows, count, logmon, oos
 
Constructor Summary
BufferedMessageOutputStream()
          Creates a new output stream to write data to an unspecified underlying output stream through a buffer with default size.
BufferedMessageOutputStream(int size)
          Creates a new output stream to write data to an unspecified underlying output stream through a buffer with the specified size.
 
Method Summary
 void flush()
          Flushes this output stream.
 void write(byte[] b, int off, int len)
          Writes len bytes from the specified byte array starting at offset off to this output stream.
 void write(int b)
          Writes the specified byte to this output stream.
 
Methods inherited from class fr.dyade.aaa.agent.MessageOutputStream
getLogger, write, writeHeader, writeInt, writeMessage, writeMessageHeader, writeShort
 
Methods inherited from class java.io.OutputStream
close
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

out

protected java.io.OutputStream out
The underlying output stream.

Constructor Detail

BufferedMessageOutputStream

public BufferedMessageOutputStream()
                            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 - if the internal ObjectOutputStream cannot be correctly initialized.

BufferedMessageOutputStream

public BufferedMessageOutputStream(int size)
                            throws java.io.IOException
Creates a new output stream to write data to an unspecified underlying output stream through a buffer with the 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

write

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

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

write

public final 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.

Ordinarily this method stores bytes from the given array into this stream's buffer, flushing the buffer to the underlying output stream as needed. If the requested length is at least as large as this stream's buffer, however, then this method will flush the buffer and write the bytes directly to the underlying output stream.

Specified by:
write in class MessageOutputStream
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.

flush

public final void flush()
                 throws java.io.IOException
Flushes this output stream.

This forces any buffered output bytes to be written out to the underlying output stream.

Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream
Throws:
java.io.IOException - if an I/O error occurs.


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