code: public void flush() throws IOException {
      flushBuffer(true);
      out.flush();
  
      // if buffer is big, and last query doesn't use at least half of it, resize buffer to default value
      if (buf.length > SMALL_BUFFER_SIZE && cmdLength * 2 < buf.length) {
        buf = new byte[SMALL_BUFFER_SIZE];
      }
  
      if (cmdLength >= maxAllowedPacket) {
        throw new MaxAllowedPacketException(
            "query size (" + cmdLength + ") is >= to max_allowed_packet (" + maxAllowedPacket + ")",
            true);
      }
    }
docs: Send packet to socket.
  
  @throws IOException if socket error occur.