code: private static byte[] ensureCapacity(byte[] buf, int needed) {
          if (buf.length <= needed) {
              byte[] old = buf;
              buf = new byte[Integer.highestOneBit(needed) << 1];
              System.arraycopy(old, 0, buf, 0, old.length);
          }
          return buf;
      }
docs: /*
  ensureCapacity will increase the buffer as needed, taking note that
  the new buffer will always be greater than the needed and never
  exactly equal to the needed size or bp. If equal then the read (above)
  will infinitely loop as buf.length - bp == 0.