Package com.mysql.cj.protocol.x
Class CompressionSplittedInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
com.mysql.cj.protocol.x.CompressionSplittedInputStream
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class CompressionSplittedInputStream
extends java.io.FilterInputStream
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
-
Constructor Summary
Constructors Constructor Description CompressionSplittedInputStream(java.io.InputStream in, CompressorStreamsFactory streamsFactory)
-
Method Summary
Modifier and Type Method Description int
available()
Same asInputStream.available()
, except that the exact number of bytes that can be read from the underlyingInputStream
may not be accurate until it is known if the next bytes contain compressed data or not.void
close()
Closes this stream.int
read()
Forwards the read toread(byte[], int, int)
.int
read(byte[] b)
Forwards the read toread(byte[], int, int)
.int
read(byte[] b, int off, int len)
Reads bytes from the underlyingInputStream
either from the one that gets data directly from the original sourceInputStream
or from a compressorableInputStream
, 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 underlyingInputStream
, blocking if needed.
-
Constructor Details
-
CompressionSplittedInputStream
public CompressionSplittedInputStream(java.io.InputStream in, CompressorStreamsFactory streamsFactory)
-
-
Method Details
-
available
public int available() throws java.io.IOExceptionSame asInputStream.available()
, except that the exact number of bytes that can be read from the underlyingInputStream
may not be accurate until it is known if the next bytes contain compressed data or not.- Overrides:
available
in classjava.io.FilterInputStream
- Returns:
- an approximate number of available bytes to read.
- Throws:
java.io.IOException
- See Also:
FilterInputStream.available()
-
close
public void close() throws java.io.IOExceptionCloses this stream.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
- See Also:
FilterInputStream.close()
-
read
public int read() throws java.io.IOExceptionForwards the read toread(byte[], int, int)
.- Overrides:
read
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
- See Also:
FilterInputStream.read()
-
read
public int read(byte[] b) throws java.io.IOExceptionForwards the read toread(byte[], int, int)
.- Overrides:
read
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
- See Also:
FilterInputStream.read(byte[])
-
read
public int read(byte[] b, int off, int len) throws java.io.IOExceptionReads bytes from the underlyingInputStream
either from the one that gets data directly from the original sourceInputStream
or from a compressorableInputStream
, if reading of a compressed X Protocol frame is in progress.- Overrides:
read
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
- See Also:
FilterInputStream.read(byte[], int, int)
-
readFully
public int readFully(byte[] b) throws java.io.IOExceptionReads the number of bytes required to fill the given buffer from the underlyingInputStream
, blocking if needed.- Parameters:
b
- the buffer into which the data is read.- 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. - Throws:
java.io.IOException
- if any of the underlying I/O operations fail.
-