mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-15 22:15:15 -05:00
Minor optiomization to help with the OutOfMemoryError pbs we have been getting
This commit is contained in:
parent
6caccc4ead
commit
724c0aed31
@ -138,46 +138,51 @@ public class MimeUtility {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (part != null && part.getBody() != null) {
|
if (part != null && part.getBody() != null) {
|
||||||
InputStream in = part.getBody().getInputStream();
|
Body body = part.getBody();
|
||||||
String mimeType = part.getMimeType();
|
if (body instanceof TextBody) {
|
||||||
if (mimeType != null && MimeUtility.mimeTypeMatches(mimeType, "text/*")) {
|
return ((TextBody)body).getText();
|
||||||
/*
|
}
|
||||||
* Now we read the part into a buffer for further processing. Because
|
else {
|
||||||
* the stream is now wrapped we'll remove any transfer encoding at this point.
|
InputStream in = part.getBody().getInputStream();
|
||||||
*/
|
String mimeType = part.getMimeType();
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
if (mimeType != null && MimeUtility.mimeTypeMatches(mimeType, "text/*")) {
|
||||||
IOUtils.copy(in, out);
|
/*
|
||||||
|
* 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();
|
byte[] bytes = out.toByteArray();
|
||||||
in.close();
|
in.close();
|
||||||
out.close();
|
out.close();
|
||||||
|
|
||||||
String charset = getHeaderParameter(part.getContentType(), "charset");
|
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) {
|
|
||||||
/*
|
/*
|
||||||
* 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);
|
if (charset != null) {
|
||||||
charset = mCharsetConverter.name();
|
/*
|
||||||
}
|
* See if there is conversion from the MIME charset to the Java one.
|
||||||
if (charset != null) {
|
*/
|
||||||
/*
|
mCharsetConverter = Charset.forName(charset);
|
||||||
* We've got a charset encoding, so decode using it.
|
charset = mCharsetConverter.name();
|
||||||
*/
|
}
|
||||||
return new String(bytes, 0, bytes.length, charset);
|
if (charset != null) {
|
||||||
}
|
/*
|
||||||
else {
|
* We've got a charset encoding, so decode using it.
|
||||||
/*
|
*/
|
||||||
* No encoding, so use us-ascii, which is the standard.
|
return new String(bytes, 0, bytes.length, charset);
|
||||||
*/
|
}
|
||||||
return new String(bytes, 0, bytes.length, "ASCII");
|
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) {
|
catch (Exception e) {
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user