public static ByteBuffer ensureCapacity(ByteBuffer existingBuffer, int newLength) {
        if (newLength > existingBuffer.capacity()) {
            ByteBuffer newBuffer = ByteBuffer.allocate(newLength);
            existingBuffer.flip();
            newBuffer.put(existingBuffer);
            return newBuffer;
        }
        return existingBuffer;
    }
Check if the given ByteBuffer capacity
@param existingBuffer ByteBuffer capacity to check
@param newLength new length for the ByteBuffer.
returns ByteBuffer
clients/src/main/java/org/apache/kafka/common/utils/Utils.java