Search in sources :

Example 1 with Base64DataException

use of android.util.Base64DataException in project android_packages_apps_Dialer by LineageOS.

the class MimeUtility method decodeBody.

/**
 * Removes any content transfer encoding from the stream and returns a Body.
 */
public static Body decodeBody(InputStream in, String contentTransferEncoding) throws IOException {
    /*
     * We'll remove any transfer encoding by wrapping the stream.
     */
    in = getInputStreamForContentTransferEncoding(in, contentTransferEncoding);
    BinaryTempFileBody tempBody = new BinaryTempFileBody();
    OutputStream out = tempBody.getOutputStream();
    try {
        IOUtils.copy(in, out);
    } catch (Base64DataException bde) {
    // TODO Need to fix this somehow
    // String warning = "\n\n" + Email.getMessageDecodeErrorString();
    // out.write(warning.getBytes());
    } finally {
        out.close();
    }
    return tempBody;
}
Also used : OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Base64DataException(android.util.Base64DataException)

Example 2 with Base64DataException

use of android.util.Base64DataException in project android_packages_apps_Dialer by LineageOS.

the class ImapFolder method decodeBody.

/**
 * Removes any content transfer encoding from the stream and returns a Body. This code is
 * taken/condensed from MimeUtility.decodeBody
 */
private static Body decodeBody(Context context, InputStream in, String contentTransferEncoding, int size, MessageRetrievalListener listener) throws IOException {
    // Get a properly wrapped input stream
    in = MimeUtility.getInputStreamForContentTransferEncoding(in, contentTransferEncoding);
    BinaryTempFileBody tempBody = new BinaryTempFileBody();
    OutputStream out = tempBody.getOutputStream();
    try {
        byte[] buffer = new byte[COPY_BUFFER_SIZE];
        int n = 0;
        int count = 0;
        while (-1 != (n = in.read(buffer))) {
            out.write(buffer, 0, n);
            count += n;
        }
    } catch (Base64DataException bde) {
        String warning = "\n\nThere was an error while decoding the message.";
        out.write(warning.getBytes());
    } finally {
        out.close();
    }
    return tempBody;
}
Also used : BinaryTempFileBody(com.android.voicemail.impl.mail.internet.BinaryTempFileBody) OutputStream(java.io.OutputStream) ImapString(com.android.voicemail.impl.mail.store.imap.ImapString) Base64DataException(android.util.Base64DataException)

Aggregations

Base64DataException (android.util.Base64DataException)2 OutputStream (java.io.OutputStream)2 BinaryTempFileBody (com.android.voicemail.impl.mail.internet.BinaryTempFileBody)1 ImapString (com.android.voicemail.impl.mail.store.imap.ImapString)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1