Class PacketWriter
- java.lang.Object
-
- org.mariadb.jdbc.client.socket.impl.PacketWriter
-
-
Field Summary
Fields Modifier and Type Field Description protected byte[]bufinternal bufferprotected MutableIntcompressSequencecompressed packet sequenceprotected intposbuffer positionprotected MutableIntsequencepacket sequencestatic intSMALL_BUFFER_SIZEinitial buffer size
-
Constructor Summary
Constructors Constructor Description PacketWriter(OutputStream out, int maxQuerySizeToLog, Integer maxAllowedPacket, 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 byte[]buf()Current bufferbooleanbufIsDataAfterMark()Buffer has data after marked positionvoidclose()Close socket streamvoidflush()Send packet to socket.voidflushBufferStopAtMark()Flush to last mark.longgetCmdLength()get current command lengthbooleanhasFlushed()Current command has flushed packet to socketvoidinitPacket()reset sequences and position for sending a new packetbooleanisMarked()has some position been markedvoidmark()mark positionvoidpermitTrace(boolean permitTrace)Indicate if logging trace are permittedintpos()get current positionvoidpos(int pos)position setterbyte[]resetMark()Reset mark flag and send bytes after mark flag.voidsetServerThreadId(Long serverThreadId, HostAddress hostAddress)Set server thread id.booleanthrowMaxAllowedLength(int length)must a max allowed length exception be thrownvoidwriteAscii(String str)Write ascii string to buffervoidwriteByte(int value)Write byte into buf, flush buf to socket if needed.voidwriteBytes(byte[] arr)Write byte array to buffervoidwriteBytes(byte[] arr, int off, int len)Write byte array to buf.voidwriteBytesAtPos(byte[] arr, int pos)Write byte array to buffer at a specific positionvoidwriteBytesEscaped(byte[] bytes, int len, boolean noBackslashEscapes)Write escape bytes to socket.voidwriteDouble(double value)Write Double binary value to buffervoidwriteEmptyPacket()Send empty packet.voidwriteFloat(float value)Write float binary value to buffervoidwriteInt(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)Write utf8 string to buffervoidwriteStringEscaped(String str, boolean noBackslashEscapes)Write string to socket.
-
-
-
Field Detail
-
SMALL_BUFFER_SIZE
public static final int SMALL_BUFFER_SIZE
initial buffer size- See Also:
- Constant Field Values
-
buf
protected byte[] buf
internal buffer
-
pos
protected int pos
buffer position
-
sequence
protected final MutableInt sequence
packet sequence
-
compressSequence
protected final MutableInt compressSequence
compressed packet sequence
-
-
Constructor Detail
-
PacketWriter
public PacketWriter(OutputStream out, int maxQuerySizeToLog, Integer maxAllowedPacket, MutableInt sequence, MutableInt compressSequence)
Common feature to write data into socket, creating MariaDB Packet.- Parameters:
out- output streammaxQuerySizeToLog- maximum query size to logmaxAllowedPacket- max allowed packet value if knownsequence- packet sequencecompressSequence- compressed packet sequence
-
-
Method Detail
-
pos
public int pos()
get current position
-
pos
public void pos(int pos) throws IOExceptionposition setter- Specified by:
posin interfaceWriter- Parameters:
pos- new position- Throws:
IOException- if buffer is not big enough to contains new position
-
getCmdLength
public long getCmdLength()
get current command length- Specified by:
getCmdLengthin interfaceWriter- Returns:
- current command length
-
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 IOExceptionDescription copied from interface:WriterWrite Double binary value to buffer- Specified by:
writeDoublein interfaceWriter- Parameters:
value- double value- Throws:
IOException- if socket error occur
-
writeFloat
public void writeFloat(float value) throws IOExceptionDescription copied from interface:WriterWrite float binary value to buffer- Specified by:
writeFloatin interfaceWriter- Parameters:
value- float value- Throws:
IOException- if socket error occur
-
writeBytes
public void writeBytes(byte[] arr) throws IOExceptionDescription copied from interface:WriterWrite byte array to buffer- Specified by:
writeBytesin interfaceWriter- Parameters:
arr- bytes- Throws:
IOException- if socket error occur
-
writeBytesAtPos
public void writeBytesAtPos(byte[] arr, int pos)Description copied from interface:WriterWrite byte array to buffer at a specific position- Specified by:
writeBytesAtPosin interfaceWriter- Parameters:
arr- bytespos- position
-
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
Description copied from interface:WriterWrite ascii string to buffer- Specified by:
writeAsciiin interfaceWriter- Parameters:
str- string- Throws:
IOException- if socket error occurs
-
writeString
public void writeString(String str) throws IOException
Description copied from interface:WriterWrite utf8 string to buffer- Specified by:
writeStringin interfaceWriter- Parameters:
str- string- Throws:
IOException- if socket error occurs
-
buf
public byte[] buf()
Current buffer
-
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)
Description copied from interface:Writermust a max allowed length exception be thrown- Specified by:
throwMaxAllowedLengthin interfaceWriter- Parameters:
length- command length- Returns:
- true if too big
-
permitTrace
public void permitTrace(boolean permitTrace)
Description copied from interface:WriterIndicate if logging trace are permitted- Specified by:
permitTracein interfaceWriter- Parameters:
permitTrace- permits trace to be logged
-
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
-
mark
public void mark()
Description copied from interface:Writermark position
-
isMarked
public boolean isMarked()
Description copied from interface:Writerhas some position been marked
-
hasFlushed
public boolean hasFlushed()
Description copied from interface:WriterCurrent command has flushed packet to socket- Specified by:
hasFlushedin interfaceWriter- Returns:
- indicate if some packet have been flushed
-
flushBufferStopAtMark
public void flushBufferStopAtMark() throws IOExceptionFlush to last mark.- Specified by:
flushBufferStopAtMarkin interfaceWriter- Throws:
IOException- if flush fail.
-
bufIsDataAfterMark
public boolean bufIsDataAfterMark()
Description copied from interface:WriterBuffer has data after marked position- Specified by:
bufIsDataAfterMarkin interfaceWriter- Returns:
- indicate if there is data after marked position
-
resetMark
public byte[] resetMark()
Reset mark flag and send bytes after mark flag.
-
initPacket
public void initPacket()
Description copied from interface:Writerreset sequences and position for sending a new packet- 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 IOExceptionDescription copied from interface:WriterClose socket stream- Specified by:
closein interfaceWriter- Throws:
IOException- if any error occurs
-
-