1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-08-13 17:03:48 -04:00

Minor optiomization to help with the OutOfMemoryError pbs we have been getting

This commit is contained in:
Bao-Long Nguyen-Trong 2009-05-12 05:31:21 +00:00
parent 6caccc4ead
commit 724c0aed31

View File

@ -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) {
/*