mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-24 02:12:15 -05:00
Properly closing InputStreams to avoid StrictMode warnings
This commit is contained in:
parent
9c335127e2
commit
5678786c97
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 */ }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user