InvalidXmlCharacterModifier implements Modifier { @Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("InvalidXmlCharacterModifier [\nreplacement="); builder.append(replacement); builder.append(", \nmatcher="); builder.append(matcher); builder.append(", \ndollarZero="); builder.append(dollarZero); builder.append("]"); return builder.toString(); } InvalidXmlCharacterModifier(String replacement, String xmlVersion);  InvalidXmlCharacterModifier(int newNumberOfChars, String replacement, String xmlVersion, boolean dollarZero); @Override AfterModification modify(StringBuilder characterBuffer, int firstModifiableCharacterInBuffer,
            boolean endOfStreamHit); @Override String toString(); static final String XML_10_VERSION; static final String XML_11_VERSION; }
@Test public void testExampleFromHomepage_removeInvalidCharacters() throws Exception { Reader reader = new StringReader("foo\uD8FFbar"); Modifier modifier = new InvalidXmlCharacterModifier("", InvalidXmlCharacterModifier.XML_11_VERSION); ModifyingReader modifyingReader = new ModifyingReader(reader, modifier); String actualOutput = IOUtils.toString(modifyingReader); assertEquals("foobar", actualOutput); }
@Test public void testExampleFromHomepage_replaceWithErrorMessage() throws Exception { Reader reader = new StringReader("foo\uD8FFbar"); Modifier modifier = new InvalidXmlCharacterModifier("[INVALID XML CHAR FOUND: $0]", InvalidXmlCharacterModifier.XML_11_VERSION); ModifyingReader modifyingReader = new ModifyingReader(reader, modifier); String actualOutput = IOUtils.toString(modifyingReader); assertEquals("foo[INVALID XML CHAR FOUND: U+D8FF]bar", actualOutput); }