diff -w -r1.13 OutSupport.java 157c157 < w.print(obj.toString()); --- > w.write(obj.toString()); 163,165c163,166 < int c; < while ((c=reader.read()) != -1) { < escapeChar((char)c, w); --- > char[] buf = new char[4096]; > int count; > while ((count=reader.read(buf, 0, 4096)) != -1) { > writeEscaped(buf, count, w); 169,172c170,174 < // avoid needless double-buffering (is this really more efficient?) < for (int i = 0; i < text.length(); i++) { < char c = text.charAt(i); < escapeChar(c, w); --- > int start = 0; > //cache the length, avoid to call to String.length() > int length = text.length(); > char[] buf = text.toCharArray(); > writeEscaped(buf,length,w); 175a178,203 > private final static int HIGHEST_SPECIAL = '>'+1; > static char[][] specialCharactersRepresentation = new char[HIGHEST_SPECIAL][]; > static { > specialCharactersRepresentation['&'] = "&".toCharArray(); > specialCharactersRepresentation['<'] = "<".toCharArray(); > specialCharactersRepresentation['>'] = ">".toCharArray(); > specialCharactersRepresentation['"'] = """.toCharArray(); > specialCharactersRepresentation['\''] = "'".toCharArray(); > } > private static void writeEscaped(char[] buffer, int length, JspWriter w) throws IOException{ > int start = 0; > for (int i = 0; i < length; i++) { > char c = buffer[i]; > if (c <= HIGHEST_SPECIAL) { > char[] escaped = specialCharactersRepresentation[c]; > if (escaped != null) { > if (start < i) { > w.write(buffer,start,i-start); > } > start = i+1; > w.write(escaped); > } > } > } > if (start < length) { > w.write(buffer,start,length-start); 177,190d204 < < private static void escapeChar(char c, JspWriter w) throws IOException { < if (c == '&') < w.print("&"); < else if (c == '<') < w.print("<"); < else if (c == '>') < w.print(">"); < else if (c == '"') < w.print("""); < else if (c == '\'') < w.print("'");