public void resizeIfNecessary(int size) {
    final int currentCapacity = this.array.length;
    final double loadFactor = 0.6;
    if (currentCapacity < size) {
      // Increase by a factor of 1.5x
      int growCapacity = currentCapacity + (currentCapacity >> 1);
      int newCapacity = Math.max(growCapacity, size);
      this.array = Arrays.copyOf(array, newCapacity);
      bufTooLargeCounter = RpcUtils.MAX_BUFFER_OVERSIZE_TIME;
    } else if (size > initialCapacity
        && currentCapacity * loadFactor > size
        && bufTooLargeCounter-- <= 0
        && System.currentTimeMillis() - lastShrinkTime > RpcUtils.MIN_SHRINK_INTERVAL) {
      // do not resize if it is reading the request size and do not shrink too often
      array = Arrays.copyOf(array, size + (currentCapacity - size) / 2);
      bufTooLargeCounter = RpcUtils.MAX_BUFFER_OVERSIZE_TIME;
      lastShrinkTime = System.currentTimeMillis();
    }
  }
Helper class that wraps a byte[] so that it can expand and be reused. Users should call
resizeIfNecessary to make sure the buffer has suitable capacity, and then use the array as
needed.

<p>Resizing policies: Expanding: If the required size > current capacity * 1.5, expand to the
required size, otherwise expand to current capacity * 1.5. Shrinking: If initial size < the
required size < current capacity * 0.6, and such small requests last for more than 5 times,
shrink to the middle of the required size and current capacity.
iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/AutoResizingBuffer.java