public void ensureRemaining(int remainingBytesRequired) {
        if (remainingBytesRequired > buffer.remaining())
            expandBuffer(remainingBytesRequired);
    }
Ensure there is enough space to write some number of bytes, expanding the underlying buffer if necessary.
This can be used to avoid incremental expansions through calls to {@link #write(int)} when you know how
many total bytes are needed.

@param remainingBytesRequired The number of bytes required
clients/src/main/java/org/apache/kafka/common/utils/ByteBufferOutputStream.java