diff options
Diffstat (limited to 'main/src/cgeo/geocaching/files/LocalStorage.java')
| -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; |
