use of com.fsck.k9.mail.filter.Base64OutputStream in project k-9 by k9mail.
the class BinaryTempFileBody method setEncoding.
public void setEncoding(String encoding) throws MessagingException {
if (mEncoding != null && mEncoding.equalsIgnoreCase(encoding)) {
return;
}
// The encoding changed, so we need to convert the message
if (!MimeUtil.ENC_8BIT.equalsIgnoreCase(mEncoding)) {
throw new RuntimeException("Can't convert from encoding: " + mEncoding);
}
try {
File newFile = File.createTempFile("body", null, mTempDirectory);
final OutputStream out = new FileOutputStream(newFile);
try {
OutputStream wrappedOut;
if (MimeUtil.ENC_QUOTED_PRINTABLE.equals(encoding)) {
wrappedOut = new QuotedPrintableOutputStream(out, false);
} else if (MimeUtil.ENC_BASE64.equals(encoding)) {
wrappedOut = new Base64OutputStream(out);
} else {
throw new RuntimeException("Target encoding not supported: " + encoding);
}
InputStream in = getInputStream();
try {
IOUtils.copy(in, wrappedOut);
} finally {
IOUtils.closeQuietly(in);
IOUtils.closeQuietly(wrappedOut);
}
} finally {
IOUtils.closeQuietly(out);
}
mFile = newFile;
mEncoding = encoding;
} catch (IOException e) {
throw new MessagingException("Unable to convert body", e);
}
}
use of com.fsck.k9.mail.filter.Base64OutputStream in project k-9 by k9mail.
the class BinaryAttachmentBody method writeTo.
@Override
public void writeTo(OutputStream out) throws IOException, MessagingException {
InputStream in = getInputStream();
try {
boolean closeStream = false;
if (MimeUtil.isBase64Encoding(mEncoding)) {
out = new Base64OutputStream(out);
closeStream = true;
} else if (MimeUtil.isQuotedPrintableEncoded(mEncoding)) {
out = new QuotedPrintableOutputStream(out, false);
closeStream = true;
}
try {
IOUtils.copy(in, out);
} finally {
if (closeStream) {
out.close();
}
}
} finally {
in.close();
}
}
Aggregations