Class Writer
java.lang.Object
org.mariadb.jdbc.client.socket.Writer
Packet writer
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected byte[]internal bufferprotected final MutableBytecompressed packet sequenceprotected intbuffer positionprotected final MutableBytepacket sequencestatic final intinitial buffer size -
Constructor Summary
ConstructorsConstructorDescriptionWriter(OutputStream out, int maxQuerySizeToLog, Integer maxAllowedPacket, MutableByte sequence, MutableByte compressSequence) Common feature to write data into socket, creating MariaDB Packet. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]buf()Current bufferbooleanvoidclose()voidflush()Send packet to socket.voidFlush to last mark.voidlongget current command lengthbytebooleanvoidbooleanisMarked()voidmark()voidpermitTrace(boolean permitTrace) intpos()get current positionvoidpos(int pos) position setterbyte[]Reset mark flag and send bytes after mark flag.voidsetServerThreadId(Long serverThreadId, HostAddress hostAddress) Set server thread id.booleanthrowMaxAllowedLength(int length) booleanthrowMaxAllowedLengthOr16M(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) voidSend 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 Details
-
SMALL_BUFFER_SIZE
public static final int SMALL_BUFFER_SIZEinitial buffer size- See Also:
-
sequence
packet sequence -
compressSequence
compressed packet sequence -
buf
protected byte[] bufinternal buffer -
pos
protected int posbuffer position
-
-
Constructor Details
-
Writer
public Writer(OutputStream out, int maxQuerySizeToLog, Integer maxAllowedPacket, MutableByte sequence, MutableByte 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 Details
-
pos
public int pos()get current position- Returns:
- current position
-
pos
position setter- Parameters:
pos- new position- Throws:
IOException- if buffer is not big enough to contains new position
-
getCmdLength
public long getCmdLength()get current command length- Returns:
- current command length
-
writeByte
Write byte into buf, flush buf to socket if needed.- Parameters:
value- byte to send- Throws:
IOException- if socket error occur.
-
writeShort
Write short value into buf. flush buf if too small.- Parameters:
value- short value- Throws:
IOException- if socket error occur
-
writeInt
Write int value into buf. flush buf if too small.- Parameters:
value- int value- Throws:
IOException- if socket error occur
-
writeLong
Write long value into buf. flush buf if too small.- Parameters:
value- long value- Throws:
IOException- if socket error occur
-
writeDouble
- Throws:
IOException
-
writeFloat
- Throws:
IOException
-
writeBytes
- Throws:
IOException
-
writeBytesAtPos
public void writeBytesAtPos(byte[] arr, int pos) -
writeBytes
Write byte array to buf. If buf is full, flush socket.- Parameters:
arr- byte arrayoff- offsetlen- byte length to write- Throws:
IOException- if socket error occur
-
writeLength
Write field length into buf, flush socket if needed.- Parameters:
length- field length- Throws:
IOException- if socket error occur.
-
writeAscii
- Throws:
IOException
-
writeString
- Throws:
IOException
-
buf
public byte[] buf()Current buffer- Returns:
- current buffer
-
writeStringEscaped
Write string to socket.- Parameters:
str- stringnoBackslashEscapes- escape method- Throws:
IOException- if socket error occur
-
writeBytesEscaped
Write escape bytes to socket.- Parameters:
bytes- byteslen- len to writenoBackslashEscapes- escape method- Throws:
IOException- if socket error occur
-
writeEmptyPacket
Send empty packet.- Throws:
IOException- if socket error occur.
-
flush
Send packet to socket.- Throws:
IOException- if socket error occur.
-
flushPipeline
- Throws:
IOException
-
throwMaxAllowedLength
public boolean throwMaxAllowedLength(int length) -
throwMaxAllowedLengthOr16M
public boolean throwMaxAllowedLengthOr16M(int length) -
permitTrace
public void permitTrace(boolean permitTrace) -
setServerThreadId
Set server thread id.- Parameters:
serverThreadId- current server thread id.hostAddress- host information
-
mark
public void mark() -
isMarked
public boolean isMarked() -
hasFlushed
public boolean hasFlushed() -
flushBufferStopAtMark
Flush to last mark.- Throws:
IOException- if flush fail.
-
bufIsDataAfterMark
public boolean bufIsDataAfterMark() -
resetMark
public byte[] resetMark()Reset mark flag and send bytes after mark flag.- Returns:
- bytes after mark flag
-
initPacket
public void initPacket() -
writeSocket
Flush the internal buf.- Parameters:
commandEnd- command end- Throws:
IOException- id connection error occur.
-
close
- Throws:
IOException
-
getSequence
public byte getSequence()
-