Java 类org.apache.commons.lang3.text.translate.UnicodeUnescaper 实例源码

项目:maker    文件:Lang3Test.java   
@Test
public void escape() throws UnsupportedEncodingException {
    String unicode = new UnicodeEscaper().translate("中国");
    System.out.println(unicode); // \u4E2D\u56FD
    String chinese = new UnicodeUnescaper().translate(unicode);
    System.out.println(chinese); // 中国
    System.out.println(StringEscapeUtils.escapeJava(chinese)); // \u4E2D\u56FD
    System.out.println(StringEscapeUtils.unescapeJava(unicode)); // 中国
    System.out.println(StringEscapeUtils.unescapeJson(unicode)); // 中国
    String ns = new String(unicode.getBytes("UTF-8"), "UTF-8");
    System.out.println(ns);
}