/** * Checks a set of characters, throws IOException if invalid */ public static void checkCharacters(char[] cbuf, int off, int len) throws IOException { int end = off + len; while(off<end) checkCharacter(cbuf[off++]); }
/** * Encodes a single character and returns its String representation * or null if no modification is necessary. * * @see XhtmlValidator#checkCharacter(char) * * @throws IOException if any text character cannot be converted to XHTML */ private static String getEscapedCharacter(char c) throws IOException { // 0.0037849858401 ms per call with switch // 0.00360391125522 ms per call with if, no room to improve here switch(c) { case '<': return "<"; case '>': return ">"; case '&': return "&"; default: XhtmlValidator.checkCharacter(c); return null; } }
/** * Checks a set of characters, throws IOException if invalid */ public static void checkCharacters(CharSequence str, int off, int end) throws IOException { while(off<end) checkCharacter(str.charAt(off++)); }
@Override public void write(int c) throws IOException { checkCharacter((char)c); out.write(c); }
@Override public XhtmlValidator append(char c) throws IOException { checkCharacter(c); out.append(c); return this; } }