UTF-8 转 UNIcode

针对中文显示乱码
private String encodeQuotedPrintable(final String str) {
    if (TextUtils.isEmpty(str)) {
        return "";
    }
    final StringBuilder builder = new StringBuilder();
    int index = 0;
    int lineCount = 0;
    byte[] strArray = null;

    try {
        strArray = str.getBytes("UTF-8");
    } catch (UnsupportedEncodingException e) {
        strArray = str.getBytes();
    }
    while (index < strArray.length) {
        builder.append(String.format("=%02X", strArray[index]));
        index += 1;
        lineCount += 3;

        if (lineCount >= 67) {
            // Specification requires CRLF must be inserted before the
            // length of the line
            // becomes more than 76.
            // Assuming that the next character is a multi-byte character,
            // it will become
            // 6 bytes.
            // 76 - 6 - 3 = 67
            builder.append("=\r\n");
            lineCount = 0;
        }
    }
    return builder.toString();
}


你可能感兴趣的:(message)