Class AbstractPacketOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- org.mariadb.jdbc.internal.io.output.AbstractPacketOutputStream
-
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable,PacketOutputStream
- Direct Known Subclasses:
CompressPacketOutputStream,StandardPacketOutputStream
public abstract class AbstractPacketOutputStream extends FilterOutputStream implements PacketOutputStream
-
-
Field Summary
Fields Modifier and Type Field Description protected byte[]bufprotected longcmdLengthprotected intmaxAllowedPacketprotected intmaxQuerySizeToLogprotected booleanpermitTraceprotected intposprotected intseqNoprotected StringserverThreadLogprotected longthreadIdprotected LruTraceCachetraceCache-
Fields inherited from class java.io.FilterOutputStream
out
-
-
Constructor Summary
Constructors Constructor Description AbstractPacketOutputStream(OutputStream out, int maxQuerySizeToLog, long threadId)Common feature to write data into socket, creating MariaDB Packet.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanbufferIsDataAfterMark()voidcheckMaxAllowedLength(int length)Count query size.booleancheckRemainingSize(int len)booleanexceedMaxLength()voidflush()Send packet to socket.protected abstract voidflushBuffer(boolean commandEnd)voidflushBufferStopAtMark()Flush to last mark.intgetMaxAllowedPacket()abstract intgetMaxPacketLength()OutputStreamgetOutputStream()booleanisMarked()voidmark()voidpermitTrace(boolean permitTrace)byte[]resetMark()Reset mark flag and send bytes after mark flag.abstract voidsetMaxAllowedPacket(int maxAllowedPacket)voidsetServerThreadId(long serverThreadId, Boolean isMaster)Set server thread id.voidsetTraceCache(LruTraceCache traceCache)abstract voidstartPacket(int seqNo)voidwrite(byte[] arr)voidwrite(byte[] arr, int off, int len)Write byte array to buffer.voidwrite(int value)Write byte into buffer, flush buffer to socket if needed.voidwrite(InputStream is, boolean escape, boolean noBackslashEscapes)Write stream into socket.voidwrite(InputStream is, long length, boolean escape, boolean noBackslashEscapes)Write stream into socket.voidwrite(Reader reader, boolean escape, boolean noBackslashEscapes)Write reader into socket.voidwrite(Reader reader, long length, boolean escape, boolean noBackslashEscapes)Write reader into socket.voidwrite(String str)voidwrite(String str, boolean escape, boolean noBackslashEscapes)Write string to socket.voidwriteBytes(byte value, int len)Write byte value, len times into buffer.voidwriteBytesEscaped(byte[] bytes, int len, boolean noBackslashEscapes)Write escape bytes to socket.abstract voidwriteEmptyPacket()voidwriteEmptyPacket(int seqNo)Send empty packet.voidwriteFieldLength(long length)Write field length into buffer, flush socket if needed.voidwriteInt(int value)Write int value into buffer.voidwriteLong(long value)Write long value into buffer.voidwriteShort(short value)Write short value into buffer.-
Methods inherited from class java.io.FilterOutputStream
close
-
Methods inherited from class java.io.OutputStream
nullOutputStream
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.mariadb.jdbc.internal.io.output.PacketOutputStream
close, initialPacketPos
-
-
-
-
Field Detail
-
maxQuerySizeToLog
protected final int maxQuerySizeToLog
-
buf
protected byte[] buf
-
pos
protected int pos
-
maxAllowedPacket
protected int maxAllowedPacket
-
cmdLength
protected long cmdLength
-
permitTrace
protected boolean permitTrace
-
seqNo
protected int seqNo
-
serverThreadLog
protected String serverThreadLog
-
traceCache
protected LruTraceCache traceCache
-
threadId
protected long threadId
-
-
Constructor Detail
-
AbstractPacketOutputStream
public AbstractPacketOutputStream(OutputStream out, int maxQuerySizeToLog, long threadId)
Common feature to write data into socket, creating MariaDB Packet.- Parameters:
out- socket outputStreammaxQuerySizeToLog- maximum query size to logthreadId- thread id
-
-
Method Detail
-
getMaxPacketLength
public abstract int getMaxPacketLength()
-
startPacket
public abstract void startPacket(int seqNo)
- Specified by:
startPacketin interfacePacketOutputStream
-
flushBuffer
protected abstract void flushBuffer(boolean commandEnd) throws IOException- Throws:
IOException
-
writeEmptyPacket
public void writeEmptyPacket(int seqNo) throws IOExceptionSend empty packet.- Specified by:
writeEmptyPacketin interfacePacketOutputStream- Parameters:
seqNo- packet sequence- Throws:
IOException- if socket error occur.
-
writeEmptyPacket
public abstract void writeEmptyPacket() throws IOException- Specified by:
writeEmptyPacketin interfacePacketOutputStream- Throws:
IOException
-
flush
public void flush() throws IOExceptionSend packet to socket.- Specified by:
flushin interfaceFlushable- Specified by:
flushin interfacePacketOutputStream- Overrides:
flushin classFilterOutputStream- Throws:
IOException- if socket error occur.
-
checkRemainingSize
public boolean checkRemainingSize(int len)
- Specified by:
checkRemainingSizein interfacePacketOutputStream
-
checkMaxAllowedLength
public void checkMaxAllowedLength(int length) throws MaxAllowedPacketExceptionCount query size. If query size is greater than max_allowed_packet and nothing has been already send, throw an exception to avoid having the connection closed.- Specified by:
checkMaxAllowedLengthin interfacePacketOutputStream- Parameters:
length- additional length to query size- Throws:
MaxAllowedPacketException- if query has not to be send.
-
exceedMaxLength
public boolean exceedMaxLength()
- Specified by:
exceedMaxLengthin interfacePacketOutputStream
-
getOutputStream
public OutputStream getOutputStream()
- Specified by:
getOutputStreamin interfacePacketOutputStream
-
writeShort
public void writeShort(short value) throws IOExceptionWrite short value into buffer. flush buffer if too small.- Specified by:
writeShortin interfacePacketOutputStream- Parameters:
value- short value- Throws:
IOException- if socket error occur
-
writeInt
public void writeInt(int value) throws IOExceptionWrite int value into buffer. flush buffer if too small.- Specified by:
writeIntin interfacePacketOutputStream- Parameters:
value- int value- Throws:
IOException- if socket error occur
-
writeLong
public void writeLong(long value) throws IOExceptionWrite long value into buffer. flush buffer if too small.- Specified by:
writeLongin interfacePacketOutputStream- Parameters:
value- long value- Throws:
IOException- if socket error occur
-
writeBytes
public void writeBytes(byte value, int len) throws IOExceptionWrite byte value, len times into buffer. flush buffer if too small.- Specified by:
writeBytesin interfacePacketOutputStream- Parameters:
value- byte valuelen- number of time to write value.- Throws:
IOException- if socket error occur.
-
writeFieldLength
public void writeFieldLength(long length) throws IOExceptionWrite field length into buffer, flush socket if needed.- Specified by:
writeFieldLengthin interfacePacketOutputStream- Parameters:
length- field length- Throws:
IOException- if socket error occur.
-
write
public void write(int value) throws IOExceptionWrite byte into buffer, flush buffer to socket if needed.- Specified by:
writein interfacePacketOutputStream- Overrides:
writein classFilterOutputStream- Parameters:
value- byte to send- Throws:
IOException- if socket error occur.
-
write
public void write(byte[] arr) throws IOException- Specified by:
writein interfacePacketOutputStream- Overrides:
writein classFilterOutputStream- Throws:
IOException
-
write
public void write(byte[] arr, int off, int len) throws IOExceptionWrite byte array to buffer. If buffer is full, flush socket.- Specified by:
writein interfacePacketOutputStream- Overrides:
writein classFilterOutputStream- Parameters:
arr- byte arrayoff- offsetlen- byte length to write- Throws:
IOException- if socket error occur
-
write
public void write(String str) throws IOException
- Specified by:
writein interfacePacketOutputStream- Throws:
IOException
-
write
public void write(String str, boolean escape, boolean noBackslashEscapes) throws IOException
Write string to socket.- Specified by:
writein interfacePacketOutputStream- Parameters:
str- stringescape- must be escapenoBackslashEscapes- escape method- Throws:
IOException- if socket error occur
-
write
public void write(InputStream is, boolean escape, boolean noBackslashEscapes) throws IOException
Write stream into socket.- Specified by:
writein interfacePacketOutputStream- Parameters:
is- inputStreamescape- must be escapenoBackslashEscapes- escape method- Throws:
IOException- if socket error occur
-
write
public void write(InputStream is, long length, boolean escape, boolean noBackslashEscapes) throws IOException
Write stream into socket.- Specified by:
writein interfacePacketOutputStream- Parameters:
is- inputStreamlength- write lengthescape- must be escapenoBackslashEscapes- escape method- Throws:
IOException- if socket error occur
-
write
public void write(Reader reader, boolean escape, boolean noBackslashEscapes) throws IOException
Write reader into socket.- Specified by:
writein interfacePacketOutputStream- Parameters:
reader- readerescape- must be escapenoBackslashEscapes- escape method- Throws:
IOException- if socket error occur
-
write
public void write(Reader reader, long length, boolean escape, boolean noBackslashEscapes) throws IOException
Write reader into socket.- Specified by:
writein interfacePacketOutputStream- Parameters:
reader- readerlength- write lengthescape- must be escapenoBackslashEscapes- 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 interfacePacketOutputStream- Parameters:
bytes- byteslen- len to writenoBackslashEscapes- escape method- Throws:
IOException- if socket error occur
-
getMaxAllowedPacket
public int getMaxAllowedPacket()
- Specified by:
getMaxAllowedPacketin interfacePacketOutputStream
-
setMaxAllowedPacket
public abstract void setMaxAllowedPacket(int maxAllowedPacket)
- Specified by:
setMaxAllowedPacketin interfacePacketOutputStream
-
permitTrace
public void permitTrace(boolean permitTrace)
- Specified by:
permitTracein interfacePacketOutputStream
-
setServerThreadId
public void setServerThreadId(long serverThreadId, Boolean isMaster)Set server thread id.- Specified by:
setServerThreadIdin interfacePacketOutputStream- Parameters:
serverThreadId- current server thread id.isMaster- is server master
-
setTraceCache
public void setTraceCache(LruTraceCache traceCache)
- Specified by:
setTraceCachein interfacePacketOutputStream
-
mark
public void mark()
- Specified by:
markin interfacePacketOutputStream
-
isMarked
public boolean isMarked()
- Specified by:
isMarkedin interfacePacketOutputStream
-
flushBufferStopAtMark
public void flushBufferStopAtMark() throws IOExceptionFlush to last mark.- Specified by:
flushBufferStopAtMarkin interfacePacketOutputStream- Throws:
IOException- if flush fail.
-
bufferIsDataAfterMark
public boolean bufferIsDataAfterMark()
- Specified by:
bufferIsDataAfterMarkin interfacePacketOutputStream
-
resetMark
public byte[] resetMark()
Reset mark flag and send bytes after mark flag.- Specified by:
resetMarkin interfacePacketOutputStream- Returns:
- bytes after mark flag
-
-