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

public Class CompressionSplittedInputStream

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

An InputStream wrapper that analyzes X Protocol frames and, if compressed, routes them to a secondary compressor-able InputStream that also knows how to rebuild uncompressed X Protocol frames from compressed ones.

Field Summary

Modifier and TypeField and Description
private boolean
private InputStream
private CompressorStreamsFactory
private byte[]
private int
private int
private int
private byte[]
private XMessageHeader
Inherited from java.io.FilterInputStream:
in

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

an approximate number of available bytes to read.
available
()

Overrides java.io.FilterInputStream.available.

Same as InputStream#available(), except that the exact number of bytes that can be read from the underlying InputStream may not be accurate until it is known if the next bytes contain compressed data or not.

public void
close()

Overrides java.io.FilterInputStream.close.

Implements java.io.Closeable.close.

Closes this stream.

private void
ensureOpen()

Ensures that this InputStream wasn't closed yet.

private boolean

Returns:

true if there is compressed data available, false otherwise.
isCompressedDataAvailable
()

Checks if there is data available in the compressed InputStream to be consumed.

private boolean

Returns:

true if all compressed data was consumed, false otherwise.
isCompressedDataReadComplete
()

Checks if all data from the compressed InputStream was fully consumed.

private boolean

Returns:

true if the type of current frame is com.mysql.cj.x.protobuf.Mysqlx.ServerMessages.Type#COMPRESSION, false otherwise.
isCompressedFrame
()

Checks if current X Protocol frame is compressed.

private boolean

Returns:

true if this frame's bytes weren't all consumed yet, false otherwise.
isDataAvailable
()

Checks if there is data available to be consumed.

pack-priv boolean

Returns:

true if the frame header was fully consumed, false otherwise.
isFrameHeaderFullyConsumed
()

Checks if the X Protocol frame header was fully consumed.

private MysqlxConnection.Compression

Returns:

The Protobuf Compression message.
parseCompressedMessage
()

Parses the next X Protocol message as a compressed one.

private void
peekNextFrame()

Checks the header of the next X Protocol frame and, depending on its type, sets up this class to read from an alternative compressor able underlying InputStream.

public int
public int
read(byte[]
the buffer into which the data is read.
b
)

Overrides java.io.FilterInputStream.read.

Forwards the read to read(byte[], int, int).

public int
read(byte[]
the buffer into which the data is read.
b
,
int
the start offset in array b at which the data is written.
off
,
int
the maximum number of bytes to read.
len
)

Overrides java.io.FilterInputStream.read.

Reads bytes from the underlying InputStream either from the one that gets data directly from the original source InputStream or from a compressor able InputStream, if reading of a compressed X Protocol frame is in progress.

public int

Returns:

the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
readFully
(byte[]
the buffer into which the data is read.
b
)

Reads the number of bytes required to fill the given buffer from the underlying InputStream, blocking if needed.

private final int

Returns:

the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
readFully
(byte[]
the buffer into which the data is read.
b
,
int
the start offset in the destination array b
off
,
int
the maximum number of bytes read.
len
)

Reads the exact number of requested bytes from the underlying InputStream, blocking if needed.

private final int

Returns:

the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
readFully
(InputStream
input stream to read from
inStream
,
byte[]
the buffer into which the data is read.
b
,
int
the start offset in the destination array b
off
,
int
the maximum number of bytes read.
len
)

Reads the exact number of requested bytes from the given InputStream, blocking if needed.

Inherited from java.io.FilterInputStream:
markmarkSupportedresetskip

Field Detail

closedback to summary
private boolean closed
compressorInback to summary
private InputStream compressorIn
compressorIoStreamsFactoryback to summary
private CompressorStreamsFactory compressorIoStreamsFactory
frameHeaderback to summary
private byte[] frameHeader
frameHeaderConsumedback to summary
private int frameHeaderConsumed
framePayloadConsumedback to summary
private int framePayloadConsumed
framePayloadLengthback to summary
private int framePayloadLength
singleByteback to summary
private byte[] singleByte
xMessageHeaderback to summary
private XMessageHeader xMessageHeader

Constructor Detail

CompressionSplittedInputStreamback to summary
public CompressionSplittedInputStream(InputStream in, CompressorStreamsFactory streamsFactory)

Method Detail

availableback to summary
public int available() throws IOException

Overrides java.io.FilterInputStream.available.

Same as InputStream#available(), except that the exact number of bytes that can be read from the underlying InputStream may not be accurate until it is known if the next bytes contain compressed data or not.

Returns:int

an approximate number of available bytes to read.

Annotations
@Override
Exceptions
IOException:

Doc from java.io.FilterInputStream.available.

if an I/O error occurs.

See Also
FilterInputStream#available()
closeback to summary
public void close() throws IOException

Overrides java.io.FilterInputStream.close.

Implements java.io.Closeable.close.

Closes this stream.

Annotations
@Override
Exceptions
IOException:

Doc from java.io.FilterInputStream.close.

if an I/O error occurs.

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

Ensures that this InputStream wasn't closed yet.

Exceptions
IOException:
if this InputStream was closed.
isCompressedDataAvailableback to summary
private boolean isCompressedDataAvailable() throws IOException

Checks if there is data available in the compressed InputStream to be consumed.

Returns:boolean

true if there is compressed data available, false otherwise.

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

Checks if all data from the compressed InputStream was fully consumed.

Returns:boolean

true if all compressed data was consumed, false otherwise.

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

Checks if current X Protocol frame is compressed.

Returns:boolean

true if the type of current frame is com.mysql.cj.x.protobuf.Mysqlx.ServerMessages.Type#COMPRESSION, false otherwise.

isDataAvailableback to summary
private boolean isDataAvailable() throws IOException

Checks if there is data available to be consumed.

Returns:boolean

true if this frame's bytes weren't all consumed yet, false otherwise.

Exceptions
IOException:
if any of the underlying I/O operations fail.
isFrameHeaderFullyConsumedback to summary
pack-priv boolean isFrameHeaderFullyConsumed()

Checks if the X Protocol frame header was fully consumed.

Returns:boolean

true if the frame header was fully consumed, false otherwise.

parseCompressedMessageback to summary
private MysqlxConnection.Compression parseCompressedMessage()

Parses the next X Protocol message as a compressed one.

Returns:MysqlxConnection.Compression

The Protobuf Compression message.

Annotations
@SuppressWarnings:unchecked
peekNextFrameback to summary
private void peekNextFrame() throws IOException

Checks the header of the next X Protocol frame and, depending on its type, sets up this class to read from an alternative compressor able underlying InputStream.

Exceptions
IOException:
if any of the underlying I/O operations fail.
readback to summary
public int read() throws IOException

Overrides java.io.FilterInputStream.read.

Forwards the read to read(byte[], int, int).

Returns:int

Doc from java.io.FilterInputStream.read.

the next byte of data, or -1 if the end of the stream is reached.

Annotations
@Override
Exceptions
IOException:

Doc from java.io.FilterInputStream.read.

if an I/O error occurs.

See Also
FilterInputStream#read()
readback to summary
public int read(byte[] b) throws IOException

Overrides java.io.FilterInputStream.read.

Forwards the read to read(byte[], int, int).

Parameters
b:byte[]

Doc from java.io.FilterInputStream.read.

the buffer into which the data is read.

Returns:int

Doc from java.io.FilterInputStream.read.

the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.

Annotations
@Override
Exceptions
IOException:

Doc from java.io.FilterInputStream.read.

if an I/O error occurs.

See Also
FilterInputStream#read(byte[])
readback to summary
public int read(byte[] b, int off, int len) throws IOException

Overrides java.io.FilterInputStream.read.

Reads bytes from the underlying InputStream either from the one that gets data directly from the original source InputStream or from a compressor able InputStream, if reading of a compressed X Protocol frame is in progress.

Parameters
b:byte[]

Doc from java.io.FilterInputStream.read.

the buffer into which the data is read.

off:int

Doc from java.io.FilterInputStream.read.

the start offset in array b at which the data is written.

len:int

Doc from java.io.FilterInputStream.read.

the maximum number of bytes to read.

Returns:int

Doc from java.io.FilterInputStream.read.

the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.

Annotations
@Override
Exceptions
IOException:

Doc from java.io.FilterInputStream.read.

if an I/O error occurs.

See Also
FilterInputStream#read(byte[], int, int)
readFullyback to summary
public int readFully(byte[] b) throws IOException

Reads the number of bytes required to fill the given buffer from the underlying InputStream, blocking if needed.

Parameters
b:byte[]

the buffer into which the data is read.

Returns:int

the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.

Exceptions
IOException:
if any of the underlying I/O operations fail.
readFullyback to summary
private final int readFully(byte[] b, int off, int len) throws IOException

Reads the exact number of requested bytes from the underlying InputStream, blocking if needed.

Parameters
b:byte[]

the buffer into which the data is read.

off:int

the start offset in the destination array b

len:int

the maximum number of bytes read.

Returns:int

the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.

Exceptions
IOException:
if any of the underlying I/O operations fail.
readFullyback to summary
private final int readFully(InputStream inStream, byte[] b, int off, int len) throws IOException

Reads the exact number of requested bytes from the given InputStream, blocking if needed.

Parameters
inStream:InputStream

input stream to read from

b:byte[]

the buffer into which the data is read.

off:int

the start offset in the destination array b

len:int

the maximum number of bytes read.

Returns:int

the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.

Exceptions
IOException:
if any of the underlying I/O operations fail.