StringUtils { public static String escape(String string) { if (isEmpty(string)) return ""; StringBuilder sb = new StringBuilder(); char[] chars = string.toCharArray(); for (int i = 0; i < chars.length; i++) { if (i == chars.length - 1 || chars[i] != '\r' || chars[i + 1] != '\n') { sb.append(escape(chars[i])); } } return sb.toString(); } private  StringUtils(); static String escape(String string); static String escape(char c); static String repeat(char c, int n); static String join(Iterable iterable, String separator); static String join(Iterator iterator, String separator); static String join(Object[] array, String separator); static String join(Object[] array, String separator, int startIndex, int endIndex); static boolean isEmpty(String str); static boolean isNotEmpty(String str); static int length(String str); static boolean equalsIgnoreCase(String str1, String str2); static boolean startsWith(String string, String prefix); static String substring(String str, int start); static String substring(String str, int start, int end); static String left(String str, int len); static String right(String str, int len); static String mid(String str, int pos, int len);  }
@Test public void testStringEscaping() { assertEquals(StringUtils.escape("Hallo\r\nMeister!"), "Hallo\\nMeister!"); }