我有一个带引号的文本.以下是此类文本的示例(来自维基百科文章):
如果你相信真理= 3Dbeauty,那么肯定= 20 =
数学是哲学中最美丽的分支.
我正在寻找一个Java类,它将编码形式解码为chars,例如,= 20到一个空格.
更新:感谢The Elite Gentleman,我知道我需要使用QuotedPrintableCodec:
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.net.QuotedPrintableCodec;
import org.junit.Test;
public class QuotedPrintableCodecTest {
private static final String TXT = "If you believe that truth=3Dbeauty, then surely=20=mathematics is the most beautiful branch of philosophy.";
@Test
public void processSimpleText() throws DecoderException
{
QuotedPrintableCodec.decodeQuotedPrintable( TXT.getBytes() );
}
}
Run Code Online (Sandbox Code Playgroud)
但是我一直得到以下异常:
org.apache.commons.codec.DecoderException: Invalid URL encoding: not a valid digit (radix 16): 109
at org.apache.commons.codec.net.Utils.digit16(Utils.java:44)
at org.apache.commons.codec.net.QuotedPrintableCodec.decodeQuotedPrintable(QuotedPrintableCodec.java:186)
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
更新2:我在@ SO中找到了 …
有数据:
batiment:Kube D
etage:4ème
description:some_description
Run Code Online (Sandbox Code Playgroud)
我想通过 InputStreamReader 的东西来获取这些数据:
SharedByteArrayInputStream sbais = (SharedByteArrayInputStream) content;
Reader reader = new InputStreamReader(sbais, Charset.forName("UTF8"));
int size = sbais.available();
char[] theChars = new char[size];
int data = reader.read();
int i = 0;
while (data != -1) {
theChars[i] = (char) data;
i++;
data = reader.read();
}
String parse = new String(theChars);
String[] parties = parse.split("Content-Transfer-Encoding: quoted-printable");
String partie = (parties[1]).trim();
parties = partie.split("\\R");
String ret = "";
for(String ligne : parties) {
if (ligne == null …Run Code Online (Sandbox Code Playgroud)