public class CompressionSplittedOutputStream
extends java.io.FilterOutputStream
OutputStream wrapper that analyzes X Protocol frames and routes them directly to the original underlying OutputStream or passes them
through to a compressor-able OutputStream to compresses the frame, rebuilds it and then sends a newly compressed X Protocol frame, depending on
defined data size threshold.| Modifier and Type | Field and Description |
|---|---|
private java.io.ByteArrayOutputStream |
bufferOut |
private boolean |
closed |
private boolean |
compressionEnabled |
private CompressorStreamsFactory |
compressorIoStreamsFactory |
private java.io.OutputStream |
compressorOut |
private byte[] |
frameHeader |
private int |
frameHeaderBuffered |
private int |
frameHeaderDumped |
private int |
framePayloadDumped |
private int |
framePayloadLength |
private byte[] |
singleByte |
private XMessageHeader |
xMessageHeader |
| Constructor and Description |
|---|
CompressionSplittedOutputStream(java.io.OutputStream out,
CompressorStreamsFactory ioStreamsFactory) |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes this stream.
|
private void |
ensureOpen()
Ensures that this
OutputStream wasn't closed yet. |
private void |
finalizeWrite()
Finalizes the writing of the compressed
OutputStream, if one is currently in use, by flushing it into a temporary buffer and reassembling the
original X Protocol frame into a compressed one. |
private boolean |
isFrameHeaderBuffered()
Checks if there is a complete frame header already buffered.
|
private boolean |
isFrameHeaderWriteComplete()
Checks if the entire frame X Protocol frame header has been fully written.
|
private boolean |
isPayloadWriteReady()
Checks if the X Protocol frame payload is ready to be written on the underlying
OutputStream. |
private boolean |
isWriteComplete()
Checks if current X Protocol frame has been fully written.
|
private int |
peekFrameHeader(byte[] b,
int off,
int len)
Captures the first bytes of each X Protocol frame into a byte buffer.
|
void |
write(byte[] b)
Forwards the write to
write(byte[], int, int); |
void |
write(byte[] b,
int off,
int len)
Analyzes the given bytes as an X Protocol frame and, depending on its size, writes it as-is in the underlying
OutputStream or rebuilds it as a
compressed X Protocol packet. |
void |
write(int b)
Forwards the write to
write(byte[], int, int); |
private CompressorStreamsFactory compressorIoStreamsFactory
private byte[] frameHeader
private int frameHeaderBuffered
private int frameHeaderDumped
private int framePayloadLength
private int framePayloadDumped
private XMessageHeader xMessageHeader
private boolean compressionEnabled
private java.io.ByteArrayOutputStream bufferOut
private java.io.OutputStream compressorOut
private byte[] singleByte
private boolean closed
public CompressionSplittedOutputStream(java.io.OutputStream out,
CompressorStreamsFactory ioStreamsFactory)
public void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.FilterOutputStreamjava.io.IOExceptionFilterOutputStream.close()public void write(int b)
throws java.io.IOException
write(byte[], int, int);write in class java.io.FilterOutputStreamjava.io.IOExceptionFilterOutputStream.write(int)public void write(byte[] b)
throws java.io.IOException
write(byte[], int, int);write in class java.io.FilterOutputStreamjava.io.IOExceptionFilterOutputStream.write(byte[])public void write(byte[] b,
int off,
int len)
throws java.io.IOException
OutputStream or rebuilds it as a
compressed X Protocol packet.write in class java.io.FilterOutputStreamjava.io.IOExceptionFilterOutputStream.write(int)private int peekFrameHeader(byte[] b,
int off,
int len)
b - the data.off - the start offset in the data.len - the number of bytes to write.private boolean isFrameHeaderBuffered()
true if the frame header buffer is full, false otherwise.private boolean isFrameHeaderWriteComplete()
true if the frame header was written, false otherwise.private boolean isPayloadWriteReady()
OutputStream.true the payload can be written, false otherwise.private boolean isWriteComplete()
true if the frame currently in progress was fully written, false otherwise.private void finalizeWrite()
throws java.io.IOException
OutputStream, if one is currently in use, by flushing it into a temporary buffer and reassembling the
original X Protocol frame into a compressed one. Finally, writes the entire compressed frame into the underlying OutputStream.java.io.IOException - if any of the underlying I/O operations fail.private void ensureOpen()
throws java.io.IOException
OutputStream wasn't closed yet.java.io.IOException - if this OutputStream was closed.