Top Description Fields Constructors Methods
com.mysql.cj.protocol.x

public Class CompressionSplittedOutputStream

extends FilterOutputStream
Class Inheritance
Static Imports
com.mysql.cj.protocol.x.XMessageHeader.HEADER_LENGTH

An 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.

Field Summary

Modifier and TypeField and Description
private ByteArrayOutputStream
private boolean
private boolean
private CompressorStreamsFactory
private OutputStream
private byte[]
private int
private int
private int
private int
private byte[]
private XMessageHeader
Inherited from java.io.FilterOutputStream:
out

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides java.io.FilterOutputStream.close.

Implements java.io.Closeable.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

Returns:

true if the frame header buffer is full, false otherwise.
isFrameHeaderBuffered
()

Checks if there is a complete frame header already buffered.

private boolean

Returns:

true if the frame header was written, false otherwise.
isFrameHeaderWriteComplete
()

Checks if the entire frame X Protocol frame header has been fully written.

private boolean

Returns:

true the payload can be written, false otherwise.
isPayloadWriteReady
()

Checks if the X Protocol frame payload is ready to be written on the underlying OutputStream.

private boolean

Returns:

true if the frame currently in progress was fully written, false otherwise.
isWriteComplete
()

Checks if current X Protocol frame has been fully written.

private int

Returns:

the number of bytes actually buffered.
peekFrameHeader
(byte[]
the data.
b
,
int
the start offset in the data.
off
,
int
the number of bytes to write.
len
)

Captures the first bytes of each X Protocol frame into a byte buffer.

public void
write(int
the byte.
b
)

Overrides java.io.FilterOutputStream.write.

Forwards the write to write(byte[], int, int);

public void
write(byte[]
the data to be written.
b
)

Overrides java.io.FilterOutputStream.write.

Forwards the write to write(byte[], int, int);

public void
write(byte[]
the data.
b
,
int
the start offset in the data.
off
,
int
the number of bytes to write.
len
)

Overrides java.io.FilterOutputStream.write.

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.

Inherited from java.io.FilterOutputStream:
flush

Field Detail

bufferOutback to summary
private ByteArrayOutputStream bufferOut
closedback to summary
private boolean closed

Hides java.io.FilterOutputStream.closed.

compressionEnabledback to summary
private boolean compressionEnabled
compressorIoStreamsFactoryback to summary
private CompressorStreamsFactory compressorIoStreamsFactory
compressorOutback to summary
private OutputStream compressorOut
frameHeaderback to summary
private byte[] frameHeader
frameHeaderBufferedback to summary
private int frameHeaderBuffered
frameHeaderDumpedback to summary
private int frameHeaderDumped
framePayloadDumpedback to summary
private int framePayloadDumped
framePayloadLengthback to summary
private int framePayloadLength
singleByteback to summary
private byte[] singleByte
xMessageHeaderback to summary
private XMessageHeader xMessageHeader

Constructor Detail

CompressionSplittedOutputStreamback to summary
public CompressionSplittedOutputStream(OutputStream out, CompressorStreamsFactory ioStreamsFactory)

Method Detail

closeback to summary
public void close() throws IOException

Overrides java.io.FilterOutputStream.close.

Implements java.io.Closeable.close.

Closes this stream.

Annotations
@Override
Exceptions
IOException:

Doc from java.io.FilterOutputStream.close.

if an I/O error occurs.

See Also
FilterOutputStream#close()
ensureOpenback to summary
private void ensureOpen() throws IOException

Ensures that this OutputStream wasn't closed yet.

Exceptions
IOException:
if this OutputStream was closed.
finalizeWriteback to summary
private void finalizeWrite() throws IOException

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. Finally, writes the entire compressed frame into the underlying OutputStream.

Exceptions
IOException:
if any of the underlying I/O operations fail.
isFrameHeaderBufferedback to summary
private boolean isFrameHeaderBuffered()

Checks if there is a complete frame header already buffered.

Returns:boolean

true if the frame header buffer is full, false otherwise.

isFrameHeaderWriteCompleteback to summary
private boolean isFrameHeaderWriteComplete()

Checks if the entire frame X Protocol frame header has been fully written.

Returns:boolean

true if the frame header was written, false otherwise.

isPayloadWriteReadyback to summary
private boolean isPayloadWriteReady()

Checks if the X Protocol frame payload is ready to be written on the underlying OutputStream.

Returns:boolean

true the payload can be written, false otherwise.

isWriteCompleteback to summary
private boolean isWriteComplete()

Checks if current X Protocol frame has been fully written.

Returns:boolean

true if the frame currently in progress was fully written, false otherwise.

peekFrameHeaderback to summary
private int peekFrameHeader(byte[] b, int off, int len)

Captures the first bytes of each X Protocol frame into a byte buffer.

Parameters
b:byte[]

the data.

off:int

the start offset in the data.

len:int

the number of bytes to write.

Returns:int

the number of bytes actually buffered.

writeback to summary
public void write(int b) throws IOException

Overrides java.io.FilterOutputStream.write.

Forwards the write to write(byte[], int, int);

Parameters
b:int

Doc from java.io.FilterOutputStream.write.

the byte.

Annotations
@Override
Exceptions
IOException:

Doc from java.io.FilterOutputStream.write.

if an I/O error occurs.

See Also
FilterOutputStream#write(int)
writeback to summary
public void write(byte[] b) throws IOException

Overrides java.io.FilterOutputStream.write.

Forwards the write to write(byte[], int, int);

Parameters
b:byte[]

Doc from java.io.FilterOutputStream.write.

the data to be written.

Annotations
@Override
Exceptions
IOException:

Doc from java.io.FilterOutputStream.write.

if an I/O error occurs.

See Also
FilterOutputStream#write(byte[])
writeback to summary
public void write(byte[] b, int off, int len) throws IOException

Overrides java.io.FilterOutputStream.write.

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.

Parameters
b:byte[]

Doc from java.io.FilterOutputStream.write.

the data.

off:int

Doc from java.io.FilterOutputStream.write.

the start offset in the data.

len:int

Doc from java.io.FilterOutputStream.write.

the number of bytes to write.

Annotations
@Override
Exceptions
IOException:

Doc from java.io.FilterOutputStream.write.

if an I/O error occurs.

See Also
java.io.FilterOutputStream#write(int)