1 18 package org.apache.tools.ant.filters; 19 20 import java.io.IOException ; 21 import java.io.Reader ; 22 23 38 public class EscapeUnicode 39 extends BaseParamFilterReader 40 implements ChainableReader { 41 private StringBuffer unicodeBuf; 44 45 50 public EscapeUnicode() { 51 super(); 52 unicodeBuf = new StringBuffer (); 53 } 54 55 61 public EscapeUnicode(final Reader in) { 62 super(in); 63 unicodeBuf = new StringBuffer (); 64 } 65 66 76 public final int read() throws IOException { 77 if (!getInitialized()) { 78 initialize(); 79 setInitialized(true); 80 } 81 82 int ch = -1; 83 if (unicodeBuf.length() == 0) { 84 ch = in.read(); 85 if (ch != -1) { 86 char achar = (char) ch; 87 if (achar >= '\u0080') { 88 unicodeBuf = new StringBuffer ("u0000"); 89 String s = Integer.toHexString(ch); 90 for (int i = 0; i < s.length(); i++) { 92 unicodeBuf.setCharAt(unicodeBuf.length() 93 - s.length() + i, 94 s.charAt(i)); 95 } 96 ch = '\\'; 97 } 98 } 99 } else { 100 ch = (int) unicodeBuf.charAt(0); 101 unicodeBuf.deleteCharAt(0); 102 } 103 return ch; 104 } 105 106 116 public final Reader chain(final Reader rdr) { 117 EscapeUnicode newFilter = new EscapeUnicode(rdr); 118 newFilter.setInitialized(true); 119 return newFilter; 120 } 121 122 125 private void initialize() { 126 } 127 } 128 129 | Popular Tags |