java的quoted-printable解码器源代码

来源:互联网 发布:求众数java 编辑:程序博客网 时间:2024/06/08 14:49

转自  http://www.qqread.com/java/c572396600.html


package test;import java.io.ByteArrayOutputStream;public class QuotedPrintable {public static void main(String[] args) {String a = "=BC=DA=A5=DF=A7Q=B3=A1=B8=A8=AE=E6=A1G[=AEi=C4=FD=B3]=ADp]HELLO INDUSTRY 4.0=A1A=A4u=B7~4.0=AE=C9=A5N=A5=BF=A6=A1=B1=D2=B0=CA=A1COLILY x OYA presents";String b = qpDecoding(a);System.out.println(b);}/** * QuotedPrintable 解码 * @param str * @return */public final static String qpDecoding(String str) {if (str == null) {return "";}try {str = str.replaceAll("=\n", "");byte[] bytes = str.getBytes("US-ASCII");for (int i = 0; i < bytes.length; i++) {byte b = bytes[i];if (b != 95) {bytes[i] = b;} else {bytes[i] = 32;}}if (bytes == null) {return "";}ByteArrayOutputStream buffer = new ByteArrayOutputStream();for (int i = 0; i < bytes.length; i++) {int b = bytes[i];if (b == '=') {try {int u = Character.digit((char) bytes[++i], 16);int l = Character.digit((char) bytes[++i], 16);if (u == -1 || l == -1) {continue;}buffer.write((char) ((u << 4) + l));} catch (ArrayIndexOutOfBoundsException e) {e.printStackTrace();}} else {buffer.write(b);}}return new String(buffer.toByteArray(), "big5");// big5} catch (Exception e) {e.printStackTrace();return "";}}}
输出结果:   歐立利部落格:[展覽設計]HELLOINDUSTRY4.0,工業4.0時代正式啟動。OLILYxOYApresents

0 0
原创粉丝点击