public abstract class MessageOutputStream extends OutputStream
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.
Modifier and Type | Field and Description |
---|---|
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 Logger |
logmon
Default logger for MessageOutputStream.
|
protected 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 and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
protected static 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.
|
close, flush
protected ObjectOutputStream oos
protected byte[] buf
protected int count
protected boolean compressedFlows
protected static Logger logmon
private static final byte STREAM_MAGIC1
private static final byte STREAM_MAGIC2
private static final byte STREAM_VERSION1
private static final byte STREAM_VERSION2
public MessageOutputStream() throws IOException
IOException
- an error occurs.public MessageOutputStream(int size) throws IOException
size
- the buffer size.IllegalArgumentException
- if size is less than 0.IOException
- if the internal ObjectOutputStream cannot be
correctly initialized.protected static Logger getLogger()
public abstract void write(int b) throws IOException
write
in class OutputStream
b
- the byte to be written.IOException
- if an I/O error occurs.public final void write(byte[] b) throws IOException
b.length
bytes to this output stream.
This method calls its write
method of three arguments with
the arguments b
, 0
, and b.length
.
write
in class OutputStream
b
- the data to be written.IOException
- if an I/O error occurs.OutputStream.write(byte[], int, int)
public abstract void write(byte[] b, int off, int len) throws IOException
len
bytes from the specified byte array starting
at offset off
to this output stream.write
in class OutputStream
b
- the data.off
- the start offset in the data.len
- the number of bytes to write.IOException
- if an I/O error occurs.protected final void writeShort(short s)
s
- the data.protected final void writeInt(int i)
i
- the data.protected abstract void writeHeader() throws IOException
IOException
- if an I/O error occurs.protected final void writeMessageHeader(Message msg)
msg
- The message to write out.protected final void writeMessage(Message msg, long time) throws IOException
msg
- The message to write out.time
- The current time in milliseconds, this parameter
is used to the handling of notification expiration.IOException
- if an I/O error occurs.Copyright © 2022 ScalAgent D.T.. All rights reserved.