public static ByteBuffer expandByteBufferAtMost(final ByteBuffer buf, final int maxLength) {
        final int newCapacity = maxLength > RAFT_DATA_BUF_SIZE || maxLength <= 0 ? RAFT_DATA_BUF_SIZE : maxLength;
        final ByteBuffer newBuf = ByteBuffer.allocate(buf.capacity() + newCapacity);
        BufferUtils.flip(buf);
        newBuf.put(buf);
        return newBuf;
    }
Expand byte buffer at most maxLength.
jraft-core/src/main/java/com/alipay/sofa/jraft/util/Utils.java