Class Reader
java.lang.Object
org.mariadb.jdbc.client.socket.Reader
Packet reader
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intServer-independent ceiling applied to received packets once authentication completes when nomaxAllowedPacketis configured.private final byte[]private final InputStreamprivate static final Loggerprivate static final intprivate IntegerMaximum packet size accepted (1Mb before authentication completes).private final intprivate final ReadableByteBufprivate static final intprivate final byte[]private final MutableByteprivate String -
Constructor Summary
ConstructorsConstructorDescriptionReader(InputStream in, Configuration conf, MutableByte sequence) Constructor of standard socket MySQL packet stream reader. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidcheckMaxAllowedLength(long length) voidclose()readableBufFromArray(byte[] buf) private voidreadFully(byte[] dest, int length) Read exactlylengthbytes from the socket into the beginning ofdest.private intprivate byte[]readMultiPacket(byte[] firstFragment, boolean traceEnable) Reassemble a MySQL packet split over several 16Mb fragments.byte[]readPacket(boolean traceEnable) Get the next MySQL packet.readReusablePacket(boolean traceEnable) voidsetMaxAllowedPacket(Integer maxAllowedPacket) Set the maximum size (in bytes) of a packet the reader will accept.voidsetServerThreadId(Long serverThreadId, HostAddress hostAddress) Set server thread id.
-
Field Details
-
REUSABLE_BUFFER_LENGTH
private static final int REUSABLE_BUFFER_LENGTH- See Also:
-
MAX_PACKET_SIZE
private static final int MAX_PACKET_SIZE- See Also:
-
logger
-
header
private final byte[] header -
reusableArray
private final byte[] reusableArray -
inputStream
-
maxQuerySizeToLog
private final int maxQuerySizeToLog -
sequence
-
readBuf
-
serverThreadLog
-
DEFAULT_MAX_RECEIVE_PACKET
private static final int DEFAULT_MAX_RECEIVE_PACKETServer-independent ceiling applied to received packets once authentication completes when nomaxAllowedPacketis configured. Set to a quarter of the JVM max heap, clamped between 16Mb and 1Gb -
maxAllowedPacket
Maximum packet size accepted (1Mb before authentication completes).
-
-
Constructor Details
-
Reader
Constructor of standard socket MySQL packet stream reader.- Parameters:
in- streamconf- connection optionssequence- current increment sequence
-
-
Method Details
-
readableBufFromArray
-
readReusablePacket
- Throws:
IOException
-
readReusablePacket
- Throws:
IOException
-
readPacket
Get the next MySQL packet. If the packet is more than 16M, read as many packets needed to finish reading MySQL packet. (first that has no length = 16Mb)- Parameters:
traceEnable- must trace packet.- Returns:
- array packet.
- Throws:
IOException- if socket exception occur.
-
readMultiPacket
Reassemble a MySQL packet split over several 16Mb fragments. Fragments are buffered as they arrive and copied once into the final array: growing and copying the accumulated content for every fragment would copy O(n²/16Mb) bytes for an n-byte packet.- Parameters:
firstFragment- first (full 16Mb) fragment, already readtraceEnable- must trace packet- Returns:
- complete packet content
- Throws:
IOException- if socket exception occur
-
readFully
Read exactlylengthbytes from the socket into the beginning ofdest.- Parameters:
dest- destination arraylength- number of bytes to read- Throws:
IOException- if socket exception occur or the stream ends early
-
setMaxAllowedPacket
Set the maximum size (in bytes) of a packet the reader will accept. Called once the handshake/authentication phase is over to raise the limit from the 1Mb connection-phase cap to the configuredmaxAllowedPacket.- Parameters:
maxAllowedPacket- maximum received packet size, ornullto use the default heap-relative ceiling
-
checkMaxAllowedLength
- Throws:
MaxAllowedPacketException
-
getSequence
-
close
- Throws:
IOException
-
setServerThreadId
Set server thread id.- Parameters:
serverThreadId- current server thread id.hostAddress- host information
-
readHeader
- Throws:
IOException
-