Class CompressPacketOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- org.mariadb.jdbc.internal.io.output.AbstractPacketOutputStream
-
- org.mariadb.jdbc.internal.io.output.CompressPacketOutputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
,PacketOutputStream
public class CompressPacketOutputStream extends AbstractPacketOutputStream
-
-
Field Summary
Fields Modifier and Type Field Description private int
compressSeqNo
private static byte[]
EMPTY_ARRAY
private byte[]
header
private boolean
lastPacketExactMaxPacketLength
private static Logger
logger
private static int
MAX_PACKET_LENGTH
private int
maxPacketLength
private static float
MIN_COMPRESSION_RATIO
private static int
MIN_COMPRESSION_SIZE
private byte[]
remainingData
private byte[]
subHeader
-
Fields inherited from class org.mariadb.jdbc.internal.io.output.AbstractPacketOutputStream
buf, cmdLength, maxAllowedPacket, maxQuerySizeToLog, permitTrace, pos, seqNo, serverThreadLog, threadId, traceCache
-
-
Constructor Summary
Constructors Constructor Description CompressPacketOutputStream(java.io.OutputStream out, int maxQuerySizeToLog, long threadId)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
flushBuffer(boolean commandEnd)
Flush the internal buffer.int
getMaxPacketLength()
int
initialPacketPos()
void
setMaxAllowedPacket(int maxAllowedPacket)
void
startPacket(int compressSeqNo)
void
writeEmptyPacket()
Write an empty packet.-
Methods inherited from class org.mariadb.jdbc.internal.io.output.AbstractPacketOutputStream
bufferIsDataAfterMark, checkMaxAllowedLength, checkRemainingSize, exceedMaxLength, flush, flushBufferStopAtMark, getMaxAllowedPacket, getOutputStream, isMarked, mark, permitTrace, resetMark, setServerThreadId, setTraceCache, write, write, write, write, write, write, write, write, write, writeBytes, writeBytesEscaped, writeEmptyPacket, writeFieldLength, writeInt, writeLong, writeShort
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.mariadb.jdbc.internal.io.output.PacketOutputStream
close
-
-
-
-
Field Detail
-
logger
private static final Logger logger
-
MAX_PACKET_LENGTH
private static final int MAX_PACKET_LENGTH
- See Also:
- Constant Field Values
-
EMPTY_ARRAY
private static final byte[] EMPTY_ARRAY
-
MIN_COMPRESSION_SIZE
private static final int MIN_COMPRESSION_SIZE
- See Also:
- Constant Field Values
-
MIN_COMPRESSION_RATIO
private static final float MIN_COMPRESSION_RATIO
- See Also:
- Constant Field Values
-
header
private final byte[] header
-
subHeader
private final byte[] subHeader
-
maxPacketLength
private int maxPacketLength
-
compressSeqNo
private int compressSeqNo
-
remainingData
private byte[] remainingData
-
lastPacketExactMaxPacketLength
private boolean lastPacketExactMaxPacketLength
-
-
Method Detail
-
getMaxPacketLength
public int getMaxPacketLength()
- Specified by:
getMaxPacketLength
in classAbstractPacketOutputStream
-
setMaxAllowedPacket
public void setMaxAllowedPacket(int maxAllowedPacket)
- Specified by:
setMaxAllowedPacket
in interfacePacketOutputStream
- Specified by:
setMaxAllowedPacket
in classAbstractPacketOutputStream
-
startPacket
public void startPacket(int compressSeqNo)
- Specified by:
startPacket
in interfacePacketOutputStream
- Specified by:
startPacket
in classAbstractPacketOutputStream
-
initialPacketPos
public int initialPacketPos()
-
flushBuffer
protected void flushBuffer(boolean commandEnd) throws java.io.IOException
Flush the internal buffer.Compression add a 7 header :
- 3 byte compression length
- 1 byte compress sequence number
- 3 bytes uncompress length
in case packet isn't compressed (last 3 bytes == 0):
- 3 byte uncompress length
- 1 byte compress sequence number
- 3 bytes with 0 value
Content correspond to standard content.
- 3 byte length
- 1 byte sequence number (!= than compress sequence number)
- sub-content
Problem is when standard content is bigger than 16mb : content will not send 4byte standard header + 16mb content, since packet are limited to 16mb then 4 bytes standard header + 16mb - 4 bytes content. the ending 4 bytes are waiting to be send. next packet will then send the waiting data before next packet, putting more waiting data is needed. if ending data is exactly MAX_PACKET_LENGTH length, then an empty packet must be send.
- Specified by:
flushBuffer
in classAbstractPacketOutputStream
- Parameters:
commandEnd
- command end- Throws:
java.io.IOException
- id connection error occur.
-
writeEmptyPacket
public void writeEmptyPacket() throws java.io.IOException
Write an empty packet.- Specified by:
writeEmptyPacket
in interfacePacketOutputStream
- Specified by:
writeEmptyPacket
in classAbstractPacketOutputStream
- Throws:
java.io.IOException
- if socket error occur.
-
-