EscapeUtils { private static String unescape(String line) { int len = line.length(); StringBuilder sb = new StringBuilder(len - 1); for (int i = 0; i < len; i++) { char c = line.charAt(i); if (c == '\\') { checkState(i < len - 1, "Expected one more char after '\\' at [%s] in [%s]", i, line); char nextChar = line.charAt(i + 1); switch (nextChar) { case 'n': sb.append('\n'); i++; break; case 'r': sb.append('\r'); i++; break; case '\\': sb.append('\\'); i++; break; default: String msg = String.format("Unexpected char [%c] found at %d of [%s]. " + "Expected '\\' or 'r' or 'n", nextChar, i, line); throw new IllegalArgumentException(msg); } } else { sb.append(c); } } return sb.toString(); }  static String escapeLineBreak(@Nullable String line); static String unescapeLineBreaks(@Nullable String line);  }
@Test public void testUnEscape() throws Exception{ assertEquals("ab\nc\r", EscapeUtils.unescapeLineBreaks("ab\\nc\\r")); assertEquals("a\\z", EscapeUtils.unescapeLineBreaks("a\\\\z")); assertEquals("some text with multi \nbyte 田中 characters.", EscapeUtils.unescapeLineBreaks("some text with multi \\nbyte 田中 characters.")); }