From 724c0aed3141ba71f367f8672c9e259074e0757b Mon Sep 17 00:00:00 2001 From: Bao-Long Nguyen-Trong Date: Tue, 12 May 2009 05:31:21 +0000 Subject: [PATCH] Minor optiomization to help with the OutOfMemoryError pbs we have been getting --- .../email/mail/internet/MimeUtility.java | 73 ++++++++++--------- 1 file changed, 39 insertions(+), 34 deletions(-) diff --git a/src/com/android/email/mail/internet/MimeUtility.java b/src/com/android/email/mail/internet/MimeUtility.java index 505bb7b81..e3879ffa7 100644 --- a/src/com/android/email/mail/internet/MimeUtility.java +++ b/src/com/android/email/mail/internet/MimeUtility.java @@ -138,46 +138,51 @@ public class MimeUtility { try { if (part != null && part.getBody() != null) { - InputStream in = part.getBody().getInputStream(); - String mimeType = part.getMimeType(); - if (mimeType != null && MimeUtility.mimeTypeMatches(mimeType, "text/*")) { - /* - * Now we read the part into a buffer for further processing. Because - * the stream is now wrapped we'll remove any transfer encoding at this point. - */ - ByteArrayOutputStream out = new ByteArrayOutputStream(); - IOUtils.copy(in, out); + Body body = part.getBody(); + if (body instanceof TextBody) { + return ((TextBody)body).getText(); + } + else { + InputStream in = part.getBody().getInputStream(); + String mimeType = part.getMimeType(); + if (mimeType != null && MimeUtility.mimeTypeMatches(mimeType, "text/*")) { + /* + * Now we read the part into a buffer for further processing. Because + * the stream is now wrapped we'll remove any transfer encoding at this point. + */ + ByteArrayOutputStream out = new ByteArrayOutputStream(); + IOUtils.copy(in, out); - byte[] bytes = out.toByteArray(); - in.close(); - out.close(); + byte[] bytes = out.toByteArray(); + in.close(); + out.close(); - String charset = getHeaderParameter(part.getContentType(), "charset"); - /* - * We've got a text part, so let's see if it needs to be processed further. - */ - if (charset != null) { + String charset = getHeaderParameter(part.getContentType(), "charset"); /* - * See if there is conversion from the MIME charset to the Java one. + * We've got a text part, so let's see if it needs to be processed further. */ - mCharsetConverter = Charset.forName(charset); - charset = mCharsetConverter.name(); - } - if (charset != null) { - /* - * We've got a charset encoding, so decode using it. - */ - return new String(bytes, 0, bytes.length, charset); - } - else { - /* - * No encoding, so use us-ascii, which is the standard. - */ - return new String(bytes, 0, bytes.length, "ASCII"); + if (charset != null) { + /* + * See if there is conversion from the MIME charset to the Java one. + */ + mCharsetConverter = Charset.forName(charset); + charset = mCharsetConverter.name(); + } + if (charset != null) { + /* + * We've got a charset encoding, so decode using it. + */ + return new String(bytes, 0, bytes.length, charset); + } + else { + /* + * No encoding, so use us-ascii, which is the standard. + */ + return new String(bytes, 0, bytes.length, "ASCII"); + } } } - } - + }//if text body } catch (Exception e) { /*