public RingBuffer trimEnd() {
        // Move length backward.
        if (length > 0) {
            // Find the end offset.
            int off = offset + length - 1;
            off = off % buffer.length;

            while (buffer[off] <= SPACE && length > 0) {
                if (off == 0) {
                    off = buffer.length;
                }

                off--;
                length--;
            }
        }

        return this;
    }
Create a buffer with a specified initial size.

@param initialSize The initial size of the buffer.
stroom-pipeline/src/main/java/stroom/pipeline/xml/converter/ds3/RingBuffer.java