Class PacketWriter
- java.lang.Object
-
- org.mariadb.jdbc.client.socket.impl.PacketWriter
-
-
Field Summary
Fields Modifier and Type Field Description protected byte[]
buf
protected MutableInt
compressSequence
protected int
pos
protected MutableInt
sequence
static int
SMALL_BUFFER_SIZE
-
Constructor Summary
Constructors Constructor Description PacketWriter(OutputStream out, int maxQuerySizeToLog, MutableInt sequence, MutableInt compressSequence)
Common feature to write data into socket, creating MariaDB Packet.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
bufIsDataAfterMark()
void
close()
void
flush()
Send packet to socket.void
flushBufferStopAtMark()
Flush to last mark.long
getCmdLength()
boolean
hasFlushed()
void
initPacket()
boolean
isMarked()
void
mark()
void
permitTrace(boolean permitTrace)
int
pos()
void
pos(int pos)
byte[]
resetMark()
Reset mark flag and send bytes after mark flag.void
setMaxAllowedPacket(int maxAllowedPacket)
void
setServerThreadId(Long serverThreadId, HostAddress hostAddress)
Set server thread id.boolean
throwMaxAllowedLength(int length)
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, boolean noBackslashEscapes)
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, boolean noBackslashEscapes)
Write string to socket.
-
-
-
Field Detail
-
SMALL_BUFFER_SIZE
public static final int SMALL_BUFFER_SIZE
- See Also:
- Constant Field Values
-
sequence
protected final MutableInt sequence
-
compressSequence
protected final MutableInt compressSequence
-
buf
protected byte[] buf
-
pos
protected int pos
-
-
Constructor Detail
-
PacketWriter
public PacketWriter(OutputStream out, int maxQuerySizeToLog, MutableInt sequence, MutableInt compressSequence)
Common feature to write data into socket, creating MariaDB Packet.- Parameters:
out
- output streammaxQuerySizeToLog
- maximum query size to logsequence
- packet sequencecompressSequence
- compressed packet sequence
-
-
Method Detail
-
pos
public void pos(int pos) throws IOException
- Specified by:
pos
in interfaceWriter
- Throws:
IOException
-
getCmdLength
public long getCmdLength()
- Specified by:
getCmdLength
in interfaceWriter
-
writeByte
public void writeByte(int value) throws IOException
Write byte into buf, flush buf to socket if needed.- Specified by:
writeByte
in interfaceWriter
- Parameters:
value
- byte to send- Throws:
IOException
- if socket error occur.
-
writeShort
public void writeShort(short value) throws IOException
Write short value into buf. flush buf if too small.- Specified by:
writeShort
in interfaceWriter
- Parameters:
value
- short value- Throws:
IOException
- if socket error occur
-
writeInt
public void writeInt(int value) throws IOException
Write int value into buf. flush buf if too small.- Specified by:
writeInt
in interfaceWriter
- Parameters:
value
- int value- Throws:
IOException
- if socket error occur
-
writeLong
public void writeLong(long value) throws IOException
Write long value into buf. flush buf if too small.- Specified by:
writeLong
in interfaceWriter
- Parameters:
value
- long value- Throws:
IOException
- if socket error occur
-
writeDouble
public void writeDouble(double value) throws IOException
- Specified by:
writeDouble
in interfaceWriter
- Throws:
IOException
-
writeFloat
public void writeFloat(float value) throws IOException
- Specified by:
writeFloat
in interfaceWriter
- Throws:
IOException
-
writeBytes
public void writeBytes(byte[] arr) throws IOException
- Specified by:
writeBytes
in interfaceWriter
- Throws:
IOException
-
writeBytesAtPos
public void writeBytesAtPos(byte[] arr, int pos)
- Specified by:
writeBytesAtPos
in interfaceWriter
-
writeBytes
public void writeBytes(byte[] arr, int off, int len) throws IOException
Write byte array to buf. If buf is full, flush socket.- Specified by:
writeBytes
in interfaceWriter
- Parameters:
arr
- byte arrayoff
- offsetlen
- byte length to write- Throws:
IOException
- if socket error occur
-
writeLength
public void writeLength(long length) throws IOException
Write field length into buf, flush socket if needed.- Specified by:
writeLength
in interfaceWriter
- Parameters:
length
- field length- Throws:
IOException
- if socket error occur.
-
writeAscii
public void writeAscii(String str) throws IOException
- Specified by:
writeAscii
in interfaceWriter
- Throws:
IOException
-
writeString
public void writeString(String str) throws IOException
- Specified by:
writeString
in interfaceWriter
- Throws:
IOException
-
writeStringEscaped
public void writeStringEscaped(String str, boolean noBackslashEscapes) throws IOException
Write string to socket.- Specified by:
writeStringEscaped
in interfaceWriter
- Parameters:
str
- stringnoBackslashEscapes
- escape method- Throws:
IOException
- if socket error occur
-
writeBytesEscaped
public void writeBytesEscaped(byte[] bytes, int len, boolean noBackslashEscapes) throws IOException
Write escape bytes to socket.- Specified by:
writeBytesEscaped
in interfaceWriter
- Parameters:
bytes
- byteslen
- len to writenoBackslashEscapes
- escape method- Throws:
IOException
- if socket error occur
-
writeEmptyPacket
public void writeEmptyPacket() throws IOException
Send empty packet.- Specified by:
writeEmptyPacket
in interfaceWriter
- Throws:
IOException
- if socket error occur.
-
flush
public void flush() throws IOException
Send packet to socket.- Specified by:
flush
in interfaceWriter
- Throws:
IOException
- if socket error occur.
-
throwMaxAllowedLength
public boolean throwMaxAllowedLength(int length)
- Specified by:
throwMaxAllowedLength
in interfaceWriter
-
setMaxAllowedPacket
public void setMaxAllowedPacket(int maxAllowedPacket)
- Specified by:
setMaxAllowedPacket
in interfaceWriter
-
permitTrace
public void permitTrace(boolean permitTrace)
- Specified by:
permitTrace
in interfaceWriter
-
setServerThreadId
public void setServerThreadId(Long serverThreadId, HostAddress hostAddress)
Set server thread id.- Specified by:
setServerThreadId
in interfaceWriter
- Parameters:
serverThreadId
- current server thread id.hostAddress
- host information
-
hasFlushed
public boolean hasFlushed()
- Specified by:
hasFlushed
in interfaceWriter
-
flushBufferStopAtMark
public void flushBufferStopAtMark() throws IOException
Flush to last mark.- Specified by:
flushBufferStopAtMark
in interfaceWriter
- Throws:
IOException
- if flush fail.
-
bufIsDataAfterMark
public boolean bufIsDataAfterMark()
- Specified by:
bufIsDataAfterMark
in interfaceWriter
-
resetMark
public byte[] resetMark()
Reset mark flag and send bytes after mark flag.
-
initPacket
public void initPacket()
- Specified by:
initPacket
in interfaceWriter
-
writeSocket
protected void writeSocket(boolean commandEnd) throws IOException
Flush the internal buf.- Parameters:
commandEnd
- command end- Throws:
IOException
- id connection error occur.
-
close
public void close() throws IOException
- Specified by:
close
in interfaceWriter
- Throws:
IOException
-
-