1 25 package classycle.util; 26 27 import java.io.BufferedReader ; 28 import java.io.File ; 29 import java.io.FileReader ; 30 import java.io.IOException ; 31 32 37 public class Text 38 { 39 private static final String ESCAPE_CHARACTERS = "<>&\"'"; 40 private static final String [] ESCAPE_SEQUENCES = new String [] { 41 "<", ">", "&", """, "'"}; 42 private Text() {} 43 44 50 public static String excapeForXML(String text) 51 { 52 StringBuffer buffer = new StringBuffer (); 53 for (int i = 0, n = text.length(); i < n; i++) 54 { 55 char c = text.charAt(i); 56 int index = ESCAPE_CHARACTERS.indexOf(c); 57 if (index < 0) 58 { 59 buffer.append(c); 60 } else 61 { 62 buffer.append(ESCAPE_SEQUENCES[index]); 63 } 64 } 65 return new String (buffer); 66 } 67 68 74 public static String readTextFile(File file) throws IOException 75 { 76 StringBuffer buffer = new StringBuffer (); 77 BufferedReader reader 78 = new BufferedReader (new FileReader (file)); 79 String line; 80 while ((line = reader.readLine()) != null) 81 { 82 buffer.append(line).append('\n'); 83 } 84 String result = new String (buffer); 85 return result; 86 } 87 88 } 89 | Popular Tags |