EscapeUtils { private static String escape(String line) { int len = line.length(); StringBuilder sb = new StringBuilder(len + 1); for (int i = 0; i < len; i++) { char c = line.charAt(i); switch (c) { case '\n': sb.append("\\n"); break; case '\r': sb.append("\\r"); break; case '\\': sb.append("\\\\"); break; default: sb.append(c); } } return sb.toString(); }  static String escapeLineBreak(@Nullable String line); static String unescapeLineBreaks(@Nullable String line);  }
@Test public void testEscape() throws Exception{ assertEquals("ab\\nc\\r", EscapeUtils.escapeLineBreak("ab\nc\r")); assertEquals("a\\\\z", EscapeUtils.escapeLineBreak("a\\z")); assertEquals("some text with multi \\nbyte 田中 characters.", EscapeUtils.escapeLineBreak("some text with multi \nbyte 田中 characters.")); }