### Question:
CleanXMLStreamWriter implements XMLStreamWriter { protected static String escapeCharacters(String string) { char[] copy = null; boolean copied = false; for (int i = 0; i < string.length();) { int codePoint = string.codePointAt(i); int size = Character.charCount(codePoint); if (!isLegalXmlCodePoint(codePoint)) { if (!copied) { copy = string.toCharArray(); copied = true; } for (int j = 0; j < size; j++) { copy[i + j] = REPLACEMENT_CHARACTER; } } i += size; } return copied ? new String(copy) : string; } CleanXMLStreamWriter(XMLStreamWriter writer); void writeStartElement(String s); void writeStartElement(String s, String s1); void writeStartElement(String s, String s1, String s2); void writeEmptyElement(String s, String s1); void writeEmptyElement(String s, String s1, String s2); void writeEmptyElement(String s); void writeEndElement(); void writeEndDocument(); void close(); void flush(); void writeAttribute(String localName, String value); void writeAttribute(String prefix, String namespaceUri, String localName, String value); void writeAttribute(String namespaceUri, String localName, String value); void writeNamespace(String s, String s1); void writeDefaultNamespace(String s); void writeComment(String s); void writeProcessingInstruction(String s); void writeProcessingInstruction(String s, String s1); void writeCData(String s); void writeDTD(String s); void writeEntityRef(String s); void writeStartDocument(); void writeStartDocument(String s); void writeStartDocument(String s, String s1); void writeCharacters(String s); void writeCharacters(char[] chars, int start, int len); String getPrefix(String s); void setPrefix(String s, String s1); void setDefaultNamespace(String s); void setNamespaceContext(NamespaceContext namespaceContext); NamespaceContext getNamespaceContext(); Object getProperty(String s); static final char REPLACEMENT_CHARACTER; }### Answer:
@Test public void testEscape() { String orig = "\uD850\uDDAC成功"; String escaped = CleanXMLStreamWriter.escapeCharacters(orig); assertEquals(orig, escaped); orig = "\uDBC0\uDCDF am 25 April 1868"; escaped = CleanXMLStreamWriter.escapeCharacters(orig); assertEquals(orig, escaped); orig = "蘇\uD849\uDF67"; escaped = CleanXMLStreamWriter.escapeCharacters(orig); assertEquals(orig, escaped); }
@Test public void testVerticalTab() { String orig = "Vertical\u000BTab"; String escaped = CleanXMLStreamWriter.escapeCharacters(orig); assertEquals("Vertical\uFFFDTab", escaped); }