Package fr.dyade.aaa.agent
Class BufferedMessageOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- fr.dyade.aaa.agent.MessageOutputStream
-
- fr.dyade.aaa.agent.BufferedMessageOutputStream
-
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
- Direct Known Subclasses:
PoolNetwork.NetSession.NetworkOutputStream,SimpleNetwork.NetworkOutputStream
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
Fields Modifier and Type Field Description protected OutputStreamoutThe underlying output stream.-
Fields inherited from class fr.dyade.aaa.agent.MessageOutputStream
buf, compressedFlows, count, oos
-
-
Constructor Summary
Constructors Constructor Description 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voiddrain()Writes the internal buffer in underlying output stream.voidflush()Flushes this output stream.voidwrite(byte[] b, int off, int len)Writeslenbytes from the specified byte array starting at offsetoffto this output stream.voidwrite(int b)Writes the specified byte to this output stream.-
Methods inherited from class fr.dyade.aaa.agent.MessageOutputStream
write, writeHeader, writeInt, writeMessage, writeMessageHeader, writeShort
-
Methods inherited from class java.io.OutputStream
close, nullOutputStream
-
-
-
-
Field Detail
-
out
protected OutputStream out
The underlying output stream.
-
-
Constructor Detail
-
BufferedMessageOutputStream
public BufferedMessageOutputStream() throws IOExceptionCreates a new output stream to write data to an unspecified underlying output stream through a buffer with default size.- Throws:
IOException- if the internal ObjectOutputStream cannot be correctly initialized.
-
BufferedMessageOutputStream
public BufferedMessageOutputStream(int size) throws IOExceptionCreates 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:
IllegalArgumentException- if size is less than 0.IOException- if the internal ObjectOutputStream cannot be correctly initialized.
-
-
Method Detail
-
drain
private final void drain() throws IOExceptionWrites the internal buffer in underlying output stream.- Throws:
IOException- an error occurs.
-
write
public final void write(int b) throws IOExceptionWrites the specified byte to this output stream.- Specified by:
writein classMessageOutputStream- Parameters:
b- the byte to be written.- Throws:
IOException- if an I/O error occurs.
-
write
public final void write(byte[] b, int off, int len) throws IOExceptionWriteslenbytes from the specified byte array starting at offsetoffto 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:
writein classMessageOutputStream- Parameters:
b- the data.off- the start offset in the data.len- the number of bytes to write.- Throws:
IOException- if an I/O error occurs.
-
flush
public final void flush() throws IOExceptionFlushes this output stream.This forces any buffered output bytes to be written out to the underlying output stream.
- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException- if an I/O error occurs.
-
-