CharsetUtil { static public String normalize(CharSequence str0, String charsetName) { Charset charset = map(charsetName); if (charset == null) { throw new IllegalArgumentException("Unsupported charset [" + charsetName + "]"); } return normalize(str0, charset); }  static HashMap<String,Charset> getCharsetMap(); static Charset map(String charsetName); static byte[] encode(CharSequence str0, String charsetName); static byte[] encode(CharSequence str0, Charset charset); static void decode(byte[] bytes, StringBuilder buffer, String charsetName); static void decode(byte[] bytes, StringBuilder buffer, Charset charset); static String decode(byte[] bytes, String charsetName); static String decode(byte[] bytes, Charset charset); static String normalize(CharSequence str0, String charsetName); static String normalize(CharSequence str0, Charset charset); static final HashMap<String,Charset> charsets; static final String NAME_ISO_8859_1; static final String NAME_ISO_8859_15; static final String NAME_GSM; static final String NAME_PACKED_GSM; static final String NAME_UCS_2; static final String NAME_UCS_2LE; static final String NAME_UTF_8; static final String NAME_MODIFIED_UTF8; static final String NAME_AIRWIDE_IA5; static final String NAME_VFD2_GSM; static final String NAME_VFTR_GSM; static final String NAME_GSM7; static final String NAME_GSM8; static final String NAME_AIRWIDE_GSM; static final String NAME_TMOBILENL_GSM; static final Charset CHARSET_ISO_8859_1; static final Charset CHARSET_ISO_8859_15; static final Charset CHARSET_GSM; static final Charset CHARSET_PACKED_GSM; static final Charset CHARSET_UCS_2; static final Charset CHARSET_UCS_2LE; static final Charset CHARSET_UTF_8; static final Charset CHARSET_MODIFIED_UTF8; static final Charset CHARSET_AIRWIDE_IA5; static final Charset CHARSET_VFD2_GSM; static final Charset CHARSET_VFTR_GSM; static final Charset CHARSET_GSM7; static final Charset CHARSET_GSM8; static final Charset CHARSET_AIRWIDE_GSM; static final Charset CHARSET_TMOBILENL_GSM; }
@Test public void normalize() throws Exception { String in = null; in = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefjhijklmnopqrstuvwxyz01234567890?&@"; for (Map.Entry<String,Charset> entry : CharsetUtil.getCharsetMap().entrySet()) { Assert.assertEquals("Charset " + entry.getKey() + " implementation broken", in, CharsetUtil.normalize(in, entry.getValue())); } in = "\u20AC"; Assert.assertEquals("\u20AC", CharsetUtil.normalize(in, CharsetUtil.CHARSET_GSM)); Assert.assertEquals("\u20AC", CharsetUtil.normalize(in, CharsetUtil.CHARSET_PACKED_GSM)); Assert.assertEquals("\u20AC", CharsetUtil.normalize(in, CharsetUtil.CHARSET_AIRWIDE_GSM)); Assert.assertEquals("\u20AC", CharsetUtil.normalize(in, CharsetUtil.CHARSET_VFD2_GSM)); Assert.assertEquals("\u20AC", CharsetUtil.normalize(in, CharsetUtil.CHARSET_VFTR_GSM)); Assert.assertEquals("?", CharsetUtil.normalize(in, CharsetUtil.CHARSET_ISO_8859_1)); Assert.assertEquals("\u20AC", CharsetUtil.normalize(in, CharsetUtil.CHARSET_ISO_8859_15)); Assert.assertEquals("\u20AC", CharsetUtil.normalize(in, CharsetUtil.CHARSET_UCS_2)); Assert.assertEquals("\u20AC", CharsetUtil.normalize(in, CharsetUtil.CHARSET_UCS_2LE)); Assert.assertEquals("\u20AC", CharsetUtil.normalize(in, CharsetUtil.CHARSET_UTF_8)); Assert.assertEquals("\u20AC", CharsetUtil.normalize(in, CharsetUtil.CHARSET_TMOBILENL_GSM)); in = "\u6025"; Assert.assertEquals("?", CharsetUtil.normalize(in, CharsetUtil.CHARSET_GSM)); Assert.assertEquals("?", CharsetUtil.normalize(in, CharsetUtil.CHARSET_PACKED_GSM)); Assert.assertEquals("?", CharsetUtil.normalize(in, CharsetUtil.CHARSET_AIRWIDE_GSM)); Assert.assertEquals("?", CharsetUtil.normalize(in, CharsetUtil.CHARSET_VFD2_GSM)); Assert.assertEquals("?", CharsetUtil.normalize(in, CharsetUtil.CHARSET_VFTR_GSM)); Assert.assertEquals("?", CharsetUtil.normalize(in, CharsetUtil.CHARSET_ISO_8859_1)); Assert.assertEquals("?", CharsetUtil.normalize(in, CharsetUtil.CHARSET_ISO_8859_15)); Assert.assertEquals("\u6025", CharsetUtil.normalize(in, CharsetUtil.CHARSET_UCS_2)); Assert.assertEquals("\u6025", CharsetUtil.normalize(in, CharsetUtil.CHARSET_UCS_2LE)); Assert.assertEquals("\u6025", CharsetUtil.normalize(in, CharsetUtil.CHARSET_UTF_8)); Assert.assertEquals("?", CharsetUtil.normalize(in, CharsetUtil.CHARSET_TMOBILENL_GSM)); }