public char[] toCharArray() {
        final char[] chars = new char[length];
        int off = offset;
        int len = length;
        int pos = 0;
        while (len > 0) {
            if (off + len > buffer.length) {
                int copied = buffer.length - off;
                System.arraycopy(buffer, off, chars, pos, copied);
                len -= copied;
                pos += copied;
                off = 0;
            } else {
                System.arraycopy(buffer, off, chars, pos, len);
                len = 0;
            }
        }

        return chars;
    }
Actually copy the buffer with the current start and end positions. The
new copy will not be affected by any changes made to the original.
stroom-util/src/test/java/stroom/util/xml/RingBuffer.java