Class Reader

java.lang.Object
org.mariadb.jdbc.client.socket.Reader

public class Reader extends Object
Packet reader
  • 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

      private static final Logger logger
    • reusableArray

      private final byte[] reusableArray
    • inputStream

      private final InputStream inputStream
    • maxQuerySizeToLog

      private final int maxQuerySizeToLog
    • sequence

      private final MutableByte sequence
    • readBuf

      private final ReadableByteBuf readBuf
    • serverThreadLog

      private String serverThreadLog
    • DEFAULT_MAX_RECEIVE_PACKET

      private static final int DEFAULT_MAX_RECEIVE_PACKET
      Server-independent ceiling applied to received packets once authentication completes when no maxAllowedPacket is configured. Set to a quarter of the JVM max heap, clamped between 16Mb and 1Gb
    • maxAllowedPacket

      private Integer maxAllowedPacket
      Maximum packet size accepted (1Mb before authentication completes).
  • Constructor Details

    • Reader

      public Reader(InputStream in, Configuration conf, MutableByte sequence)
      Constructor of standard socket MySQL packet stream reader.
      Parameters:
      in - stream
      conf - connection options
      sequence - current increment sequence
  • Method Details

    • readableBufFromArray

      public ReadableByteBuf readableBufFromArray(byte[] buf)
    • readReusablePacket

      public ReadableByteBuf readReusablePacket() throws IOException
      Throws:
      IOException
    • readReusablePacket

      public ReadableByteBuf readReusablePacket(boolean traceEnable) throws IOException
      Throws:
      IOException
    • readPacket

      public byte[] readPacket(boolean traceEnable) throws IOException
      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

      private byte[] readMultiPacket(byte[] firstFragment, boolean traceEnable) throws IOException
      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 read
      traceEnable - must trace packet
      Returns:
      complete packet content
      Throws:
      IOException - if socket exception occur
    • readFully

      private void readFully(byte[] dest, int length) throws IOException
      Read exactly length bytes from the socket into the beginning of dest.
      Parameters:
      dest - destination array
      length - number of bytes to read
      Throws:
      IOException - if socket exception occur or the stream ends early
    • setMaxAllowedPacket

      public void setMaxAllowedPacket(Integer maxAllowedPacket)
      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 configured maxAllowedPacket.
      Parameters:
      maxAllowedPacket - maximum received packet size, or null to use the default heap-relative ceiling
    • checkMaxAllowedLength

      private void checkMaxAllowedLength(long length) throws MaxAllowedPacketException
      Throws:
      MaxAllowedPacketException
    • getSequence

      public MutableByte getSequence()
    • close

      public void close() throws IOException
      Throws:
      IOException
    • setServerThreadId

      public void setServerThreadId(Long serverThreadId, HostAddress hostAddress)
      Set server thread id.
      Parameters:
      serverThreadId - current server thread id.
      hostAddress - host information
    • readHeader

      private int readHeader() throws IOException
      Throws:
      IOException