| Code with Finding: |
class Entities {
/**
* <p>
* Escapes the characters in a <code>String</code>.
* </p>
*
* <p>
* For example, if you have called addEntity("foo", 0xA1), escape("\u00A1") will return
* "&foo;"
* </p>
*
* @param str
* The <code>String</code> to escape.
* @return A new escaped <code>String</code>.
*/
public String escape(String str) {
StringWriter stringWriter = createStringWriter(str);
try {
this.escape(stringWriter, str);
} catch (IOException e) {
// This should never happen because ALL the StringWriter methods called by #escape(Writer, String) do not
// throw IOExceptions.
throw new UnhandledException(e);
}
return stringWriter.toString();
}
}
|