### Question:
Utils { public static String escape(String str, boolean escapeSingleQuote) { if (str == null) { return null; } int len = str.length(); StringWriter writer = new StringWriter(len * 2); for (int i = 0; i < len; i++) { char ch = str.charAt(i); if (ch > 0xfff) { writer.write("\\u" + hex(ch)); } else if (ch > 0xff) { writer.write("\\u0" + hex(ch)); } else if (ch > 0x7f) { writer.write("\\u00" + hex(ch)); } else if (ch < 32) { switch (ch) { case '\b': writer.write('\\'); writer.write('b'); break; case '\n': writer.write('\\'); writer.write('n'); break; case '\t': writer.write('\\'); writer.write('t'); break; case '\f': writer.write('\\'); writer.write('f'); break; case '\r': writer.write('\\'); writer.write('r'); break; default : if (ch > 0xf) { writer.write("\\u00" + hex(ch)); } else { writer.write("\\u000" + hex(ch)); } break; } } else { switch (ch) { case '\'': if (escapeSingleQuote) { writer.write('\\'); } writer.write('\''); break; case '"': writer.write('\\'); writer.write('"'); break; case '\\': writer.write('\\'); writer.write('\\'); break; case '/': writer.write('\\'); writer.write('/'); break; default : writer.write(ch); break; } } } return writer.toString(); } private  Utils(); static String join(String delimiter, String wrap, Iterable<?> objs); static String join(String delimiter, Iterable<?> objs); static String concat(CharSequence... strings); static void closeQuietly(Closeable closeable); static String escape(String str, boolean escapeSingleQuote); static String unescape(String str); static String hex(char ch); static boolean isEmpty(CharSequence cs); static T notNull(T object, String message, Object... values); static void isTrue(boolean expression, String message); static void onlyOneIsTrue(final String message, final boolean... expressions); static boolean onlyOneIsTrueNonThrow(final boolean... expressions); static T notEmpty(T chars, String message, Object... values); static String toString(Object o);  }### Answer:
@Test public void testEscape() { Assert.assertNull(Utils.escape(null, true)); Assert.assertEquals("\\\\f\\'o\\\"o\\rb\\fa\\t\\nr\\bb\\/a", Utils.escape("\\f\'o\"o\rb\fa\t\nr\bb/a", true)); Assert.assertEquals("\\uFFFF\\u0FFF\\u00FF\\u000F\\u0010", Utils.escape("\uffff\u0fff\u00ff\u000f\u0010", true)); }