To use this MimeUtility
method you have to create a ByteArrayOutputStream
which will accumulate the bytes written to it, which you can then recover. For example, to encode the string original
:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStream encodedOut = MimeUtility.encode(baos, "quoted-printable");
encodedOut.write(original.getBytes());
String encoded = baos.toString();
The encodeText
function from the same class will work on strings, but it produces Q-encoding, which is similar to quoted-printable but not quite the same:
String encoded = MimeUtility.encodeText(original, null, "Q");
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…