public class CompressedPacketSender extends java.lang.Object implements MessageSender<NativePacketPayload>
MessageSender for the compressed protocol.
TODO: add support for pre-allocated buffer for large packets (if there's a demonstrable perf improvement)| Modifier and Type | Field and Description |
|---|---|
static int |
COMP_HEADER_LENGTH |
private byte[] |
compressedPacket
Buffer to compress data to.
|
private int |
compressedPayloadLen
Length of current compressed packet.
|
private byte |
compressedSequenceId
Sequence id of compressed packet.
|
private java.util.zip.Deflater |
deflater |
static int |
MIN_COMPRESS_LEN |
private java.io.BufferedOutputStream |
outputStream |
| Constructor and Description |
|---|
CompressedPacketSender(java.io.BufferedOutputStream outputStream) |
| Modifier and Type | Method and Description |
|---|---|
private void |
addPayload(byte[] payload,
int payloadOffset,
int payloadLen)
Add and compress the payload into the compressed packet.
|
private void |
addUncompressedHeader(byte packetSequence,
int uncompressedPacketLen)
Add and compress the header for the raw packet into the compressed packet.
|
private void |
completeCompression()
Complete compression of the current payload contents to the compressed packet.
|
private void |
resetPacket() |
void |
send(byte[] packet,
int packetLen,
byte packetSequence)
Packet sender implementation for the compressed MySQL protocol.
|
private void |
sendCompressedPacket(int uncompressedPayloadLen)
Send a compressed packet.
|
void |
stop()
Shut down this packet sender and deallocate any resources.
|
MessageSender<NativePacketPayload> |
undecorate()
Return the previous PacketSender instance from the decorators chain or the current PacketSender
if it is the first entry in a chain.
|
MessageSender<NativePacketPayload> |
undecorateAll()
Return a PacketSender instance free of decorators.
|
private void |
writeCompressedHeader(int compLen,
byte seq,
int uncompLen)
Write the compressed packet header.
|
private void |
writeUncompressedHeader(int packetLen,
byte packetSequence)
Write an uncompressed packet header.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitsend, send, setMaxAllowedPacketprivate java.io.BufferedOutputStream outputStream
private java.util.zip.Deflater deflater
private byte[] compressedPacket
private byte compressedSequenceId
private int compressedPayloadLen
public static final int COMP_HEADER_LENGTH
public static final int MIN_COMPRESS_LEN
public CompressedPacketSender(java.io.BufferedOutputStream outputStream)
public void stop()
private void resetPacket()
private void addUncompressedHeader(byte packetSequence,
int uncompressedPacketLen)
packetSequence - sequence iduncompressedPacketLen - uncompressed packet lengthprivate void addPayload(byte[] payload,
int payloadOffset,
int payloadLen)
payload - payload bytespayloadOffset - offsetpayloadLen - lengthprivate void completeCompression()
private void writeCompressedHeader(int compLen,
byte seq,
int uncompLen)
throws java.io.IOException
compLen - compressed data lengthseq - sequence iduncompLen - uncompressed data lengthjava.io.IOException - if write exception occursprivate void writeUncompressedHeader(int packetLen,
byte packetSequence)
throws java.io.IOException
packetLen - packet lengthpacketSequence - sequence idjava.io.IOException - if write exception occursprivate void sendCompressedPacket(int uncompressedPayloadLen)
throws java.io.IOException
uncompressedPayloadLen - uncompressed data lengthjava.io.IOException - if write exception occurspublic void send(byte[] packet,
int packetLen,
byte packetSequence)
throws java.io.IOException
send in interface MessageSender<NativePacketPayload>packet - data bytespacketLen - packet lengthpacketSequence - sequence idjava.io.IOException - if i/o exception occurspublic MessageSender<NativePacketPayload> undecorateAll()
MessageSenderundecorateAll in interface MessageSender<NativePacketPayload>MessageSender instancepublic MessageSender<NativePacketPayload> undecorate()
MessageSenderundecorate in interface MessageSender<NativePacketPayload>MessageSender instance