private void move(final char[] buffer, final int start, final int end) {
            char c;
            int codePoint;

            outputBuffer.clear();
            for (int i = start, j = 0; i < end; i++) {
                c = buffer[i];
                codePoint = c;

                if (inRange(codePoint, DIGIT_CODEPOINTS) || inRange(codePoint, LOWERCASE_CODEPOINTS)
                        || inRange(codePoint, UPPERCASE_CODEPOINTS) || inValues(codePoint, OTHER_CODEPOINTS)) {
                    outputBuffer.append(c);
                    j++;
                } else {
                    j = encode(j, codePoint, outputBuffer);
                }

                if (j >= MAX_SAFE_LENGTH) {
                    // Add a truncation marker so we know that the original
                    // string has been truncated.
                    outputBuffer.append(TRUNC_MARKER);

                    // Get out of this loop.
                    i = end;
                }
            }
        }
Move characters from a buffer to the safe buffer making them safe in
the process.
stroom-pipeline/src/main/java/stroom/pipeline/filter/SafeXMLFilter.java