1 19 20 25 26 27 package soot.util; 28 29 import java.io.*; 30 31 33 public class EscapedWriter extends FilterWriter 34 { 35 36 public final String lineSeparator = System.getProperty("line.separator"); 37 private final int cr = lineSeparator.charAt(0); 38 private final int lf = (lineSeparator.length() == 2) ? lineSeparator.charAt(1) : -1; 39 40 41 public EscapedWriter(Writer fos) 42 { 43 super(fos); 44 } 45 46 private final StringBuffer mini = new StringBuffer (); 47 48 49 public void print(int ch) throws IOException 50 { 51 write(ch); 52 throw new RuntimeException (); 53 } 54 55 56 public void write(String s, int off, int len) throws IOException 57 { 58 for(int i = off; i < off + len; i++) 59 write(s.charAt(i)); 60 } 61 62 63 public void write(int ch) throws IOException 64 { 65 if (ch >= 32 && ch <= 126 || ch == cr || ch == lf || ch == ' ') 66 { super.write(ch); return; } 67 68 mini.setLength(0); 69 mini.append(Integer.toHexString(ch)); 70 71 while (mini.length() < 4) 72 mini.insert(0, "0"); 73 74 mini.insert(0, "\\u"); 75 for (int i = 0; i < mini.length(); i++) 76 super.write(mini.charAt(i)); 77 } 78 } 79 | Popular Tags |