code: private void growBuffer(int len) throws IOException {
      int bufferLength = buf.length;
      int newCapacity;
      if (bufferLength == SMALL_BUFFER_SIZE) {
        if (len + pos < MEDIUM_BUFFER_SIZE) {
          newCapacity = MEDIUM_BUFFER_SIZE;
        } else if (len + pos < LARGE_BUFFER_SIZE) {
          newCapacity = LARGE_BUFFER_SIZE;
        } else {
          newCapacity = getMaxPacketLength();
        }
      } else if (bufferLength == MEDIUM_BUFFER_SIZE) {
        if (len + pos < LARGE_BUFFER_SIZE) {
          newCapacity = LARGE_BUFFER_SIZE;
        } else {
          newCapacity = getMaxPacketLength();
        }
      } else if (bufferContainDataAfterMark) {
        //want to add some information to buffer without having the command Header
        //must grow buffer until having all the query
        newCapacity = Math.max(len + pos, getMaxPacketLength());
      } else {
        newCapacity = getMaxPacketLength();
      }
  
      if (mark != -1 && len + pos > newCapacity) {
        //buffer is > 16M with mark.
        //flush until mark, reset pos at beginning
        flushBufferStopAtMark();
  
        if (len + pos <= bufferLength) {
          return;
        }
  
        //need to keep all data, buffer can grow more than maxPacketLength
        //grow buffer if needed
        if (len + pos > newCapacity) {
          newCapacity = len + pos;
        }
      }
  
      byte[] newBuf = new byte[newCapacity];
      System.arraycopy(buf, 0, newBuf, 0, pos);
      buf = newBuf;
    }
docs: Buffer growing use 4 size only to avoid creating/copying that are expensive operations.
  possible size
  <ol>
  <li>SMALL_BUFFER_SIZE  = 8k (default)</li>
  <li>MEDIUM_BUFFER_SIZE = 128k</li>
  <li>LARGE_BUFFER_SIZE  = 1M</li>
  <li>getMaxPacketLength = 16M (+ 4 is using no compression)</li>
  </ol>
  
  @param len length to add