diff options
| author | Bananeweizen <bananeweizen@gmx.de> | 2013-08-22 21:24:22 +0200 |
|---|---|---|
| committer | Bananeweizen <bananeweizen@gmx.de> | 2013-08-22 21:24:22 +0200 |
| commit | 4774107cd772da5348073feeb82f3ec69044ab3c (patch) | |
| tree | 2166e9e019d2888c1e6dc274fcc00e37dc9695b7 /main/src | |
| parent | 2d84b218fc0213bb3c7fba91a30186b2cfd952ea (diff) | |
| download | cgeo-4774107cd772da5348073feeb82f3ec69044ab3c.zip cgeo-4774107cd772da5348073feeb82f3ec69044ab3c.tar.gz cgeo-4774107cd772da5348073feeb82f3ec69044ab3c.tar.bz2 | |
refactoring #3159: file copy exception handling
* as discussed on github for #3159
Diffstat (limited to 'main/src')
| -rw-r--r-- | main/src/cgeo/geocaching/files/LocalStorage.java | 23 |
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; |
