Package fr.dyade.aaa.agent
Class ByteArrayMessageOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- fr.dyade.aaa.agent.MessageOutputStream
-
- fr.dyade.aaa.agent.ByteArrayMessageOutputStream
-
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
- Direct Known Subclasses:
HttpNetwork.NetworkOutputStream
public abstract class ByteArrayMessageOutputStream extends MessageOutputStream
Class used to write messages into a byte array.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 inherited from class fr.dyade.aaa.agent.MessageOutputStream
buf, compressedFlows, count, oos
-
-
Constructor Summary
Constructors Constructor Description ByteArrayMessageOutputStream()Creates a new output stream to write data to an internal byte array with default size.ByteArrayMessageOutputStream(int size)Creates a new output stream to write data to an internal byte array with specified size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidreset()Resets this output stream.intsize()Returns the current size of the buffer.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.voidwriteTo(OutputStream out)Writes the complete contents of this byte array output stream to the specified output stream argument, as if by calling the output stream's write method usingout.write(buf, 0, count).-
Methods inherited from class fr.dyade.aaa.agent.MessageOutputStream
write, writeHeader, writeInt, writeMessage, writeMessageHeader, writeShort
-
Methods inherited from class java.io.OutputStream
close, flush, nullOutputStream
-
-
-
-
Constructor Detail
-
ByteArrayMessageOutputStream
public ByteArrayMessageOutputStream() throws IOExceptionCreates a new output stream to write data to an internal byte array with default size.- Throws:
IOException- if the internal ObjectOutputStream cannot be correctly initialized.
-
ByteArrayMessageOutputStream
public ByteArrayMessageOutputStream(int size) throws IOExceptionCreates a new output stream to write data to an internal byte array with 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
-
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.- 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.
-
size
public final int size()
Returns the current size of the buffer.- Returns:
- the current size of the buffer.
-
reset
public final void reset()
Resets this output stream.Set the
countfield of this output stream to zero, so that all currently accumulated output in the output stream is discarded. The output stream can be used again, reusing the already allocated buffer space.
-
writeTo
public final void writeTo(OutputStream out) throws IOException
Writes the complete contents of this byte array output stream to the specified output stream argument, as if by calling the output stream's write method usingout.write(buf, 0, count).- Parameters:
out- the output stream to which to write the data.- Throws:
IOException- if an I/O error occurs.
-
-