code: public static byte[] ensureCapacity(byte array[], int capacity){
          if(capacity<=0 || capacity-array.length<=0)
              return array;
  
          int newCapacity = array.length*2;
          if(newCapacity-capacity< 0)
              newCapacity = capacity;
          if(newCapacity<0){
              if(capacity<0) // overflow
                  throw new OutOfMemoryError();
              newCapacity = Integer.MAX_VALUE;
          }
          return Arrays.copyOf(array, newCapacity);
      }
docs: /*-------------------------------------------------[ ensureCapacity ]---------------------------------------------------