org.mariadb.jdbc.internal.io.output

## 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:
  Closeable, Flushable, AutoCloseable, PacketOutputStream

    public class CompressPacketOutputStream
    extends AbstractPacketOutputStream

### Field Summary

### Fields inherited from class org.mariadb.jdbc.internal.io.output.AbstractPacketOutputStream

`buf, cmdLength, logger, maxAllowedPacket, maxQuerySizeToLog, permitTrace, pos, seqNo, serverThreadLog, traceCache`

### Fields inherited from class java.io.FilterOutputStream

`out`

### Constructor Summary

Constructors
Constructor and Description
`CompressPacketOutputStream(OutputStream out, int maxQuerySizeToLog)`

### Method Summary

All Methods Instance Methods Concrete Methods
`protected void` `flushBuffer(boolean commandEnd)` Flush the internal buffer.
`int` `getMaxPacketLength()`
`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

`checkMaxAllowedLength, checkRemainingSize, flush, getMaxAllowedPacket, getOutputStream, isAllowedCmdLength, permitTrace, setServerThreadId, setTraceCache, write, write, write, write, write, write, write, write, write, writeBytes, writeBytesEscaped, writeEmptyPacket, writeFieldLength, writeInt, writeLong, writeShort`

### Methods inherited from class java.io.FilterOutputStream

`close`

### 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`

### Constructor Detail

#### CompressPacketOutputStream

    public CompressPacketOutputStream(OutputStream out,
                                      int maxQuerySizeToLog)

### Method Detail

#### getMaxPacketLength

    public int getMaxPacketLength()

Specified by:
  `getMaxPacketLength` in class `AbstractPacketOutputStream`

#### setMaxAllowedPacket

    public void setMaxAllowedPacket(int maxAllowedPacket)

Specified by:
  `setMaxAllowedPacket` in interface `PacketOutputStream`
Specified by:
  `setMaxAllowedPacket` in class `AbstractPacketOutputStream`

#### startPacket

    public void startPacket(int compressSeqNo)

Specified by:
  `startPacket` in interface `PacketOutputStream`
Specified by:
  `startPacket` in class `AbstractPacketOutputStream`

#### flushBuffer

    protected void flushBuffer(boolean commandEnd)
                        throws IOException

Flush the internal buffer.

Compression add a 7 header :

1. 3 byte compression length
2. 1 byte compress sequence number
3. 3 bytes uncompress length

in case packet isn't compressed (last 3 bytes == 0):

1. 3 byte uncompress length
2. 1 byte compress sequence number
3. 3 bytes with 0 value

Content correspond to standard content.

1. 3 byte length
2. 1 byte sequence number (!= than compress sequence number)
3. 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 class `AbstractPacketOutputStream`
Parameters:
  `commandEnd` - command end
Throws:
  `IOException` - id connection error occur.

#### writeEmptyPacket

    public void writeEmptyPacket()
                          throws IOException

Write an empty packet.

Specified by:
  `writeEmptyPacket` in interface `PacketOutputStream`
Specified by:
  `writeEmptyPacket` in class `AbstractPacketOutputStream`
Throws:
  `IOException` - if socket error occur.