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

Extract method

This commit is contained in:
cketti 2015-02-04 21:17:54 +01:00
parent 9814442de4
commit 5175ff9df4

View File

@ -3,6 +3,7 @@ package com.fsck.k9.ui.messageview;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
@ -101,19 +102,7 @@ class DownloadImageTask extends AsyncTask<String, Void, String> {
filename = getFileNameWithExtension(filename, mimeType); filename = getFileNameWithExtension(filename, mimeType);
String sanitized = FileHelper.sanitizeFilename(filename); return writeFileToStorage(filename, in);
File directory = new File(K9.getAttachmentDefaultPath());
File file = FileHelper.createUniqueFile(directory, sanitized);
FileOutputStream out = new FileOutputStream(file);
try {
IOUtils.copy(in, out);
out.flush();
} finally {
out.close();
}
return file.getName();
} finally { } finally {
if (in != null) { if (in != null) {
@ -143,6 +132,23 @@ class DownloadImageTask extends AsyncTask<String, Void, String> {
return filename + "." + extension; return filename + "." + extension;
} }
private String writeFileToStorage(String filename, InputStream in) throws IOException {
String sanitized = FileHelper.sanitizeFilename(filename);
File directory = new File(K9.getAttachmentDefaultPath());
File file = FileHelper.createUniqueFile(directory, sanitized);
FileOutputStream out = new FileOutputStream(file);
try {
IOUtils.copy(in, out);
out.flush();
} finally {
out.close();
}
return file.getName();
}
@Override @Override
protected void onPostExecute(String filename) { protected void onPostExecute(String filename) {
String text; String text;