/** * 通过使用指定的 charset 解码指定的 byte 数组,构造一个新的 String * * @param bytes * @param charsetName * @return */ public static String newString(byte[] bytes, String charsetName) { if (bytes == null) { return null; } try { return new String(bytes, charsetName); } catch (UnsupportedEncodingException e) { throw StringUtils.newIllegalStateException(charsetName, e); } }
/** * 使用指定的字符集将此 String 编码为 byte序列 * * @param string * @param charsetName 编码格式 * @return */ public static byte[] getBytesUnchecked(String string, String charsetName) { if (string == null) { return null; } try { return string.getBytes(charsetName); } catch (UnsupportedEncodingException e) { throw StringUtils.newIllegalStateException(charsetName, e); } }