aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2013-08-22 21:24:22 +0200
committerBananeweizen <bananeweizen@gmx.de>2013-08-22 21:24:22 +0200
commit4774107cd772da5348073feeb82f3ec69044ab3c (patch)
tree2166e9e019d2888c1e6dc274fcc00e37dc9695b7
parent2d84b218fc0213bb3c7fba91a30186b2cfd952ea (diff)
downloadcgeo-4774107cd772da5348073feeb82f3ec69044ab3c.zip
cgeo-4774107cd772da5348073feeb82f3ec69044ab3c.tar.gz
cgeo-4774107cd772da5348073feeb82f3ec69044ab3c.tar.bz2
refactoring #3159: file copy exception handling
* as discussed on github for #3159
-rw-r--r--main/src/cgeo/geocaching/files/LocalStorage.java23
1 files changed, 12 insertions, 11 deletions
diff --git a/main/src/cgeo/geocaching/files/LocalStorage.java b/main/src/cgeo/geocaching/files/LocalStorage.java
index e7e8a1c..fc82409 100644
--- a/main/src/cgeo/geocaching/files/LocalStorage.java
+++ b/main/src/cgeo/geocaching/files/LocalStorage.java
@@ -291,24 +291,25 @@ public final class LocalStorage {
InputStream input = null;
OutputStream output = null;
+ boolean copyDone = false;
+
try {
input = new BufferedInputStream(new FileInputStream(source));
output = new BufferedOutputStream(new FileOutputStream(destination));
- } catch (FileNotFoundException e) {
- Log.e("LocalStorage.copy: could not open file", e);
- IOUtils.closeQuietly(input);
- IOUtils.closeQuietly(output);
- return false;
- }
-
- boolean copyDone = copy(input, output);
-
- try {
+ copyDone = copy(input, output);
+ // close here already to catch any issue with closing
input.close();
output.close();
+ } catch (FileNotFoundException e) {
+ Log.e("LocalStorage.copy: could not copy file", e);
+ return false;
} catch (IOException e) {
- Log.e("LocalStorage.copy: could not close file", e);
+ Log.e("LocalStorage.copy: could not copy file", e);
return false;
+ } finally {
+ // close here quietly to clean up in all situations
+ IOUtils.closeQuietly(input);
+ IOUtils.closeQuietly(output);
}
return copyDone;