1 package org.opensrf.util;
7 * Collection of general, static utility methods
12 * Returns the string representation of a given file.
13 * @param filename The file to turn into a string
15 public static String fileToString(String filename)
16 throws FileNotFoundException, IOException {
18 StringBuffer sb = new StringBuffer();
19 BufferedReader in = new BufferedReader(new FileReader(filename));
21 while ((str = in.readLine()) != null)
29 * @see escape(String, StringBuffer)
31 public static String escape(String string) {
32 StringBuffer sb = new StringBuffer();
38 * Escapes a string. Turns bare newlines into \n, etc.
39 * Escapes \n, \r, \t, ", \f
40 * Encodes non-ascii characters as UTF-8: \u0000
41 * @param string The string to escape
42 * @param sb The string buffer to write the escaped string into
44 public static void escape(String string, StringBuffer sb) {
45 int len = string.length();
48 for( int i = 0; i < len; i++ ) {
73 if (c < 32 || c > 126 ) {
74 /* escape all non-ascii or control characters as UTF-8 */
75 utf = "000" + Integer.toHexString(c);
76 sb.append("\\u" + utf.substring(utf.length() - 4));