| Modifier and Type | Field and Description |
|---|---|
protected byte[] |
buf
internal buffer
|
protected MutableByte |
compressSequence
compressed packet sequence
|
protected int |
pos
buffer position
|
protected MutableByte |
sequence
packet sequence
|
static int |
SMALL_BUFFER_SIZE
initial buffer size
|
| Constructor and Description |
|---|
PacketWriter(OutputStream out,
int maxQuerySizeToLog,
Integer maxAllowedPacket,
MutableByte sequence,
MutableByte compressSequence)
Common feature to write data into socket, creating SingleStore Packet.
|
| Modifier and Type | Method and Description |
|---|---|
byte[] |
buf()
Current buffer
|
boolean |
bufIsDataAfterMark()
Buffer has data after marked position
|
void |
close()
Close socket stream
|
void |
flush()
Send packet to socket.
|
void |
flushBufferStopAtMark()
Flush to last mark.
|
void |
flushPipeline()
Send packet to buffered outputstream without flushing
|
long |
getCmdLength()
get current command length
|
byte |
getSequence()
Get current sequence object
|
boolean |
hasFlushed()
Current command has flushed packet to socket
|
void |
initPacket()
reset sequences and position for sending a new packet
|
boolean |
isMarked()
has some position been marked
|
void |
mark()
mark position
|
void |
permitTrace(boolean permitTrace)
Indicate if logging trace are permitted
|
int |
pos()
get current position
|
void |
pos(int pos)
position setter
|
byte[] |
resetMark()
Reset mark flag and send bytes after mark flag.
|
void |
setMaxAllowedPacket(int maxAllowedPacket)
Set max allowed packet size.
|
void |
setServerThreadId(Long serverThreadId,
HostAddress hostAddress)
Set server thread id.
|
boolean |
throwMaxAllowedLength(int length)
must a max allowed length exception be thrown
|
void |
writeAscii(String str) |
void |
writeByte(int value)
Write byte into buf, flush buf to socket if needed.
|
void |
writeBytes(byte[] arr) |
void |
writeBytes(byte[] arr,
int off,
int len)
Write byte array to buf.
|
void |
writeBytesAtPos(byte[] arr,
int pos) |
void |
writeBytesEscaped(byte[] bytes,
int len)
Write escape bytes to socket.
|
void |
writeDouble(double value) |
void |
writeEmptyPacket()
Send empty packet.
|
void |
writeFloat(float value) |
void |
writeInt(int value)
Write int value into buf.
|
void |
writeLength(long length)
Write field length into buf, flush socket if needed.
|
void |
writeLong(long value)
Write long value into buf.
|
void |
writeShort(short value)
Write short value into buf.
|
protected void |
writeSocket(boolean commandEnd)
Flush the internal buf.
|
void |
writeString(String str) |
void |
writeStringEscaped(String str)
Write string to socket.
|
public static final int SMALL_BUFFER_SIZE
protected byte[] buf
protected int pos
protected final MutableByte sequence
protected final MutableByte compressSequence
public PacketWriter(OutputStream out, int maxQuerySizeToLog, Integer maxAllowedPacket, MutableByte sequence, MutableByte compressSequence)
out - output streammaxQuerySizeToLog - maximum query size to logsequence - packet sequencemaxAllowedPacket - max allowed packet value if knowncompressSequence - compressed packet sequencepublic int pos()
public void pos(int pos)
throws IOException
pos in interface Writerpos - new positionIOException - if buffer is not big enough to contains new positionpublic long getCmdLength()
getCmdLength in interface Writerpublic void writeByte(int value)
throws IOException
writeByte in interface Writervalue - byte to sendIOException - if socket error occur.public void writeShort(short value)
throws IOException
writeShort in interface Writervalue - short valueIOException - if socket error occurpublic void setMaxAllowedPacket(int maxAllowedPacket)
WritersetMaxAllowedPacket in interface Writerpublic void writeInt(int value)
throws IOException
writeInt in interface Writervalue - int valueIOException - if socket error occurpublic void writeLong(long value)
throws IOException
writeLong in interface Writervalue - long valueIOException - if socket error occurpublic void writeDouble(double value)
throws IOException
writeDouble in interface WriterIOExceptionpublic void writeFloat(float value)
throws IOException
writeFloat in interface WriterIOExceptionpublic void writeBytes(byte[] arr)
throws IOException
writeBytes in interface WriterIOExceptionpublic void writeBytesAtPos(byte[] arr,
int pos)
writeBytesAtPos in interface Writerpublic void writeBytes(byte[] arr,
int off,
int len)
throws IOException
writeBytes in interface Writerarr - byte arrayoff - offsetlen - byte length to writeIOException - if socket error occurpublic void writeLength(long length)
throws IOException
writeLength in interface Writerlength - field lengthIOException - if socket error occur.public void writeAscii(String str) throws IOException
writeAscii in interface WriterIOExceptionpublic void writeString(String str) throws IOException
writeString in interface WriterIOExceptionpublic byte[] buf()
public void writeStringEscaped(String str) throws IOException
writeStringEscaped in interface Writerstr - stringIOException - if socket error occurpublic void writeBytesEscaped(byte[] bytes,
int len)
throws IOException
writeBytesEscaped in interface Writerbytes - byteslen - len to writeIOException - if socket error occurpublic void writeEmptyPacket()
throws IOException
writeEmptyPacket in interface WriterIOException - if socket error occur.public void flush()
throws IOException
flush in interface WriterIOException - if socket error occur.public void flushPipeline()
throws IOException
WriterflushPipeline in interface WriterIOException - if socket error occur.public boolean throwMaxAllowedLength(int length)
WriterthrowMaxAllowedLength in interface Writerlength - command lengthpublic void permitTrace(boolean permitTrace)
WriterpermitTrace in interface WriterpermitTrace - permits trace to be loggedpublic void setServerThreadId(Long serverThreadId, HostAddress hostAddress)
setServerThreadId in interface WriterserverThreadId - current server thread id.hostAddress - host informationpublic void mark()
Writerpublic boolean isMarked()
Writerpublic boolean hasFlushed()
WriterhasFlushed in interface Writerpublic void flushBufferStopAtMark()
throws IOException
flushBufferStopAtMark in interface WriterIOException - if flush fail.public boolean bufIsDataAfterMark()
WriterbufIsDataAfterMark in interface Writerpublic byte[] resetMark()
public void initPacket()
WriterinitPacket in interface Writerprotected void writeSocket(boolean commandEnd)
throws IOException
commandEnd - command endIOException - id connection error occur.public void close()
throws IOException
Writerclose in interface WriterIOException - if any error occurspublic byte getSequence()
WritergetSequence in interface WriterCopyright © 2025 SingleStore. All rights reserved.