Class PacketWriter
- java.lang.Object
-
- org.mariadb.jdbc.client.socket.impl.PacketWriter
-
-
Field Summary
Fields Modifier and Type Field Description protected byte[]bufprotected MutableIntcompressSequenceprotected intposprotected MutableIntsequencestatic intSMALL_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 booleanbufIsDataAfterMark()voidclose()voidflush()Send packet to socket.voidflushBufferStopAtMark()Flush to last mark.longgetCmdLength()booleanhasFlushed()voidinitPacket()booleanisMarked()voidmark()voidpermitTrace(boolean permitTrace)intpos()voidpos(int pos)byte[]resetMark()Reset mark flag and send bytes after mark flag.voidsetMaxAllowedPacket(int maxAllowedPacket)voidsetServerThreadId(Long serverThreadId, HostAddress hostAddress)Set server thread id.booleanthrowMaxAllowedLength(int length)voidwriteAscii(String str)voidwriteByte(int value)Write byte into buf, flush buf to socket if needed.voidwriteBytes(byte[] arr)voidwriteBytes(byte[] arr, int off, int len)Write byte array to buf.voidwriteBytesAtPos(byte[] arr, int pos)voidwriteBytesEscaped(byte[] bytes, int len, boolean noBackslashEscapes)Write escape bytes to socket.voidwriteDouble(double value)voidwriteEmptyPacket()Send empty packet.voidwriteFloat(float value)voidwriteInt(int value)Write int value into buf.voidwriteLength(long length)Write field length into buf, flush socket if needed.voidwriteLong(long value)Write long value into buf.voidwriteShort(short value)Write short value into buf.protected voidwriteSocket(boolean commandEnd)Flush the internal buf.voidwriteString(String str)voidwriteStringEscaped(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:
posin interfaceWriter- Throws:
IOException
-
getCmdLength
public long getCmdLength()
- Specified by:
getCmdLengthin interfaceWriter
-
writeByte
public void writeByte(int value) throws IOExceptionWrite byte into buf, flush buf to socket if needed.- Specified by:
writeBytein interfaceWriter- Parameters:
value- byte to send- Throws:
IOException- if socket error occur.
-
writeShort
public void writeShort(short value) throws IOExceptionWrite short value into buf. flush buf if too small.- Specified by:
writeShortin interfaceWriter- Parameters:
value- short value- Throws:
IOException- if socket error occur
-
writeInt
public void writeInt(int value) throws IOExceptionWrite int value into buf. flush buf if too small.- Specified by:
writeIntin interfaceWriter- Parameters:
value- int value- Throws:
IOException- if socket error occur
-
writeLong
public void writeLong(long value) throws IOExceptionWrite long value into buf. flush buf if too small.- Specified by:
writeLongin interfaceWriter- Parameters:
value- long value- Throws:
IOException- if socket error occur
-
writeDouble
public void writeDouble(double value) throws IOException- Specified by:
writeDoublein interfaceWriter- Throws:
IOException
-
writeFloat
public void writeFloat(float value) throws IOException- Specified by:
writeFloatin interfaceWriter- Throws:
IOException
-
writeBytes
public void writeBytes(byte[] arr) throws IOException- Specified by:
writeBytesin interfaceWriter- Throws:
IOException
-
writeBytesAtPos
public void writeBytesAtPos(byte[] arr, int pos)- Specified by:
writeBytesAtPosin interfaceWriter
-
writeBytes
public void writeBytes(byte[] arr, int off, int len) throws IOExceptionWrite byte array to buf. If buf is full, flush socket.- Specified by:
writeBytesin interfaceWriter- Parameters:
arr- byte arrayoff- offsetlen- byte length to write- Throws:
IOException- if socket error occur
-
writeLength
public void writeLength(long length) throws IOExceptionWrite field length into buf, flush socket if needed.- Specified by:
writeLengthin interfaceWriter- Parameters:
length- field length- Throws:
IOException- if socket error occur.
-
writeAscii
public void writeAscii(String str) throws IOException
- Specified by:
writeAsciiin interfaceWriter- Throws:
IOException
-
writeString
public void writeString(String str) throws IOException
- Specified by:
writeStringin interfaceWriter- Throws:
IOException
-
writeStringEscaped
public void writeStringEscaped(String str, boolean noBackslashEscapes) throws IOException
Write string to socket.- Specified by:
writeStringEscapedin interfaceWriter- Parameters:
str- stringnoBackslashEscapes- escape method- Throws:
IOException- if socket error occur
-
writeBytesEscaped
public void writeBytesEscaped(byte[] bytes, int len, boolean noBackslashEscapes) throws IOExceptionWrite escape bytes to socket.- Specified by:
writeBytesEscapedin interfaceWriter- Parameters:
bytes- byteslen- len to writenoBackslashEscapes- escape method- Throws:
IOException- if socket error occur
-
writeEmptyPacket
public void writeEmptyPacket() throws IOExceptionSend empty packet.- Specified by:
writeEmptyPacketin interfaceWriter- Throws:
IOException- if socket error occur.
-
flush
public void flush() throws IOExceptionSend packet to socket.- Specified by:
flushin interfaceWriter- Throws:
IOException- if socket error occur.
-
throwMaxAllowedLength
public boolean throwMaxAllowedLength(int length)
- Specified by:
throwMaxAllowedLengthin interfaceWriter
-
setMaxAllowedPacket
public void setMaxAllowedPacket(int maxAllowedPacket)
- Specified by:
setMaxAllowedPacketin interfaceWriter
-
permitTrace
public void permitTrace(boolean permitTrace)
- Specified by:
permitTracein interfaceWriter
-
setServerThreadId
public void setServerThreadId(Long serverThreadId, HostAddress hostAddress)
Set server thread id.- Specified by:
setServerThreadIdin interfaceWriter- Parameters:
serverThreadId- current server thread id.hostAddress- host information
-
hasFlushed
public boolean hasFlushed()
- Specified by:
hasFlushedin interfaceWriter
-
flushBufferStopAtMark
public void flushBufferStopAtMark() throws IOExceptionFlush to last mark.- Specified by:
flushBufferStopAtMarkin interfaceWriter- Throws:
IOException- if flush fail.
-
bufIsDataAfterMark
public boolean bufIsDataAfterMark()
- Specified by:
bufIsDataAfterMarkin interfaceWriter
-
resetMark
public byte[] resetMark()
Reset mark flag and send bytes after mark flag.
-
initPacket
public void initPacket()
- Specified by:
initPacketin interfaceWriter
-
writeSocket
protected void writeSocket(boolean commandEnd) throws IOExceptionFlush the internal buf.- Parameters:
commandEnd- command end- Throws:
IOException- id connection error occur.
-
close
public void close() throws IOException- Specified by:
closein interfaceWriter- Throws:
IOException
-
-