1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 19:52:17 -05:00

Properly closing InputStreams to avoid StrictMode warnings

This commit is contained in:
cketti 2012-09-05 05:57:52 +02:00
parent 9c335127e2
commit 5678786c97
2 changed files with 24 additions and 7 deletions

View File

@ -45,13 +45,16 @@ public class BinaryTempFileBody implements Body {
public void writeTo(OutputStream out) throws IOException, MessagingException {
InputStream in = getInputStream();
Base64OutputStream base64Out = new Base64OutputStream(out);
try {
IOUtils.copy(in, base64Out);
Base64OutputStream base64Out = new Base64OutputStream(out);
try {
IOUtils.copy(in, base64Out);
} finally {
base64Out.close();
}
} finally {
base64Out.close();
in.close();
}
mFile.delete();
}
class BinaryTempFileBodyInputStream extends FilterInputStream {
@ -61,8 +64,11 @@ public class BinaryTempFileBody implements Body {
@Override
public void close() throws IOException {
super.close();
mFile.delete();
try {
super.close();
} finally {
mFile.delete();
}
}
}
}

View File

@ -1061,7 +1061,18 @@ public class MimeUtility {
* the stream is now wrapped we'll remove any transfer encoding at this point.
*/
InputStream in = part.getBody().getInputStream();
return readToString(in, charset);
try {
String text = readToString(in, charset);
// Replace the body with a TextBody that already contains the decoded text
part.setBody(new TextBody(text));
return text;
} finally {
try {
in.close();
} catch (IOException e) { /* Ignore */ }
}
}
}