code: private void ensureCapacity(int minCapacity)
      {
          if (minCapacity - buffer.length > 0)
          {
              int oldCapacity = buffer.length;
              int newCapacity;
  
              if (delta < 1)
              {   // Either double internal buffer
                  newCapacity = oldCapacity << 1;
              }
              else
              {   // Increase internal buffer size by 'delta'
                  newCapacity = oldCapacity + delta;
              }
              
              if (newCapacity - minCapacity < 0)
              {
                  newCapacity = minCapacity;
              }
              buffer = Arrays.copyOf(buffer, newCapacity);
          }
      }
docs: Increases the capacity of the internal buffer (if necessary) to hold 'minCapacity' bytes.
  The internal buffer will be reallocated and expanded if necessary.  Therefore, be careful
  use the byte[] returned from getBuffer(), as it's address will change as the buffer is
  expanded.  However, if you are no longer adding to this stream, you can use the internal
  buffer.
  @param minCapacity the desired minimum capacity