code: protected void flushBuffer(boolean commandEnd) throws IOException {
      if (pos > 4) {
        buf[0] = (byte) (pos - 4);
        buf[1] = (byte) ((pos - 4) >>> 8);
        buf[2] = (byte) ((pos - 4) >>> 16);
        buf[3] = (byte) this.seqNo++;
        checkMaxAllowedLength(pos - 4);
        out.write(buf, 0, pos);
        cmdLength += pos - 4;
  
        if (traceCache != null && permitTrace) {
          //trace last packets
          traceCache.put(new TraceObject(true, NOT_COMPRESSED,
              Arrays.copyOfRange(buf, 0, pos > 1000 ? 1000 : pos)));
        }
  
        if (logger.isTraceEnabled()) {
          if (permitTrace) {
            logger.trace("send: {}{}",
                serverThreadLog,
                Utils.hexdump(maxQuerySizeToLog, 0, pos, buf));
          } else {
            logger.trace("send: content length={} {} com=<hidden>",
                pos - 4,
                serverThreadLog);
          }
        }
  
        //if last com fill the max size, must send an empty com to indicate command end.
        if (commandEnd && pos == MAX_PACKET_LENGTH) {
          writeEmptyPacket();
        }
  
        pos = 4;
      }
    }
docs: Flush the internal buffer.
  
  @param commandEnd command end
  @throws IOException id connection error occur.