To use this MimeUtility method, you must create a ByteArrayOutputStream that will accumulate the bytes recorded on it, which can then be restored. 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 with strings, but it produces Q-encoding, which is similar to quotation marks, but not quite the same :
String encoded = MimeUtility.encodeText(original, null, "Q");
source share