Ho un testo con quoted-printables. Ecco un esempio di un testo del genere (da un wikipedia article):Come decodificare i caratteri quotabili (da quotabili a un carattere)?
Se credi che la verità = 3Dbeauty, allora sicuramente = 20 =
la matematica è la più bella ramo della filosofia.
Sto cercando una classe Java, che decodificare la forma codificata di caratteri, per esempio, = 20 ad uno spazio.
UPDATE: Grazie a The Gentleman Elite, so che ho bisogno di usare 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());
}
}
Tuttavia continuo a ricevere la seguente eccezione:
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)
Che cosa sto facendo di sbagliato?
UPDATE 2: Ho trovato this question @ SO e conoscere MimeUtility:
import javax.mail.MessagingException;
import javax.mail.internet.MimeUtility;
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 MessagingException, IOException
{
InputStream is = new ByteArrayInputStream(TXT.getBytes());
BufferedReader br = new BufferedReader (new InputStreamReader( MimeUtility.decode(is, "quoted-printable")));
StringWriter writer = new StringWriter();
String line;
while((line = br.readLine()) != null)
{
writer.append(line);
}
System.out.println("INPUT: " + TXT);
System.out.println("OUTPUT: " + writer.toString());
}
}
Tuttavia l'uscita ancora non è perfetto, contiene '=':
INPUT: If you believe that truth=3Dbeauty, then surely=20= mathematics is the most beautiful branch of philosophy.
OUTPUT: If you believe that truth=beauty, then surely = mathematics is the most beautiful branch of philosophy.
Ora quello che sto facendo di sbagliato ?
Grazie per la risposta, purtroppo ricevo un'eccezione quando provo a decodificare l'esempio dalla pagina di Wikipedia. – Skarab
@Skarab, a meno che tu non ci mostri il codice e la traccia dello stack di eccezioni, non puoi pensare che la mia risposta sia negativa perché ha generato un'eccezione. Hai chiesto una lezione che decodifichi i caratteri quotabili e te l'ho mostrato. –
@Skarab, ho aggiornato il mio post al tuo esercizio di compiti a casa. Dovrei aspettarmi un +1 ora :) –