public class CompressionSplittedInputStream
extends java.io.FilterInputStream
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.| Modifier and Type | Field and Description |
|---|---|
private boolean |
closed |
private java.io.InputStream |
compressorIn |
private CompressorStreamsFactory |
compressorIoStreamsFactory |
private byte[] |
frameHeader |
private int |
frameHeaderConsumed |
private int |
framePayloadConsumed |
private int |
framePayloadLength |
private byte[] |
singleByte |
private XMessageHeader |
xMessageHeader |
| Constructor and Description |
|---|
CompressionSplittedInputStream(java.io.InputStream in,
CompressorStreamsFactory streamsFactory) |
| Modifier and Type | Method and Description |
|---|---|
int |
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. |
void |
close()
Closes this stream.
|
private void |
ensureOpen()
Ensures that this
InputStream wasn't closed yet. |
private boolean |
isCompressedDataAvailable()
Checks if there is data available in the compressed
InputStream to be consumed. |
private boolean |
isCompressedDataReadComplete()
Checks if all data from the compressed
InputStream was fully consumed. |
private boolean |
isCompressedFrame()
Checks if current X Protocol frame is compressed.
|
private boolean |
isDataAvailable()
Checks if there is data available to be consumed.
|
(package private) boolean |
isFrameHeaderFullyConsumed()
Checks if the X Protocol frame header was fully consumed.
|
private MysqlxConnection.Compression |
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. |
int |
read()
Forwards the read to
read(byte[], int, int). |
int |
read(byte[] b)
Forwards the read to
read(byte[], int, int). |
int |
read(byte[] b,
int off,
int len)
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. |
int |
readFully(byte[] b)
Reads the number of bytes required to fill the given buffer from the underlying
InputStream, blocking if needed. |
private int |
readFully(byte[] b,
int off,
int len)
Reads the exact number of requested bytes from the underlying
InputStream, blocking if needed. |
private int |
readFully(java.io.InputStream inStream,
byte[] b,
int off,
int len)
Reads the exact number of requested bytes from the given
InputStream, blocking if needed. |
private CompressorStreamsFactory compressorIoStreamsFactory
private byte[] frameHeader
private int frameHeaderConsumed
private int framePayloadLength
private int framePayloadConsumed
private XMessageHeader xMessageHeader
private java.io.InputStream compressorIn
private byte[] singleByte
private boolean closed
public CompressionSplittedInputStream(java.io.InputStream in,
CompressorStreamsFactory streamsFactory)
public int available()
throws java.io.IOException
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.available in class java.io.FilterInputStreamjava.io.IOExceptionFilterInputStream.available()public void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.FilterInputStreamjava.io.IOExceptionFilterInputStream.close()public int read()
throws java.io.IOException
read(byte[], int, int).read in class java.io.FilterInputStreamjava.io.IOExceptionFilterInputStream.read()public int read(byte[] b)
throws java.io.IOException
read(byte[], int, int).read in class java.io.FilterInputStreamjava.io.IOExceptionFilterInputStream.read(byte[])public int read(byte[] b,
int off,
int len)
throws java.io.IOException
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.read in class java.io.FilterInputStreamjava.io.IOExceptionFilterInputStream.read(byte[], int, int)private void peekNextFrame()
throws java.io.IOException
InputStream.java.io.IOException - if any of the underlying I/O operations fail.private boolean isCompressedFrame()
true if the type of current frame is Mysqlx.ServerMessages.Type.COMPRESSION, false
otherwise.private MysqlxConnection.Compression parseCompressedMessage()
MysqlxConnection.Compression message.private boolean isDataAvailable()
throws java.io.IOException
true if this frame's bytes weren't all consumed yet, false otherwise.java.io.IOException - if any of the underlying I/O operations fail.private boolean isCompressedDataAvailable()
throws java.io.IOException
InputStream to be consumed.true if there is compressed data available, false otherwise.java.io.IOException - if any of the underlying I/O operations fail.private boolean isCompressedDataReadComplete()
throws java.io.IOException
InputStream was fully consumed.true if all compressed data was consumed, false otherwise.java.io.IOException - if any of the underlying I/O operations fail.boolean isFrameHeaderFullyConsumed()
true if the frame header was fully consumed, false otherwise.public int readFully(byte[] b)
throws java.io.IOException
InputStream, blocking if needed.b - the buffer into which the data is read.-1 if there is no more data because the end of the stream has been reached.java.io.IOException - if any of the underlying I/O operations fail.private final int readFully(byte[] b,
int off,
int len)
throws java.io.IOException
InputStream, blocking if needed.b - the buffer into which the data is read.off - the start offset in the destination array blen - the maximum number of bytes read.-1 if there is no more data because the end of the stream has been reached.java.io.IOException - if any of the underlying I/O operations fail.private final int readFully(java.io.InputStream inStream,
byte[] b,
int off,
int len)
throws java.io.IOException
InputStream, blocking if needed.inStream - input stream to read fromb - the buffer into which the data is read.off - the start offset in the destination array blen - the maximum number of bytes read.-1 if there is no more data because the end of the stream has been reached.java.io.IOException - if any of the underlying I/O operations fail.private void ensureOpen()
throws java.io.IOException
InputStream wasn't closed yet.java.io.IOException - if this InputStream was closed.