From f749ddb5aed595c6294cc5873fdfc05cabd24522 Mon Sep 17 00:00:00 2001 From: Dennis Guse Date: Sun, 11 Aug 2019 19:23:40 +0200 Subject: [PATCH] Cleanup. --- README.md | 2 +- .../io/file/exporter/SaveAsyncTask.java | 16 +++++----------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 41a5662ad..aebb03d5b 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ To show your tracks on a map, a 3rd party application (e.g., [OsmAnd](https://pl ## Project history -_OpenTracks_ is based upon Google _My Tracks app_ ([code](https://code.google.com/archive/p/mytracks/). +_OpenTracks_ is based upon Google _My Tracks app_ ([code](https://code.google.com/archive/p/mytracks/)). Initially, _My Tracks_ was initially released by Google in 2010 as [open-source software](http://google-latlong.blogspot.fr/2010/05/code-for-my-tracks-is-now-yours.html). In 2016, [Google decided to discontinue](https://support.google.com/maps/answer/6333516) _My Tracks_ and stopped distributing it via the Google Play store in April 2016. The [Plonk42](https://github.com/plonk42) conducted some maintenance work until 2016, so _My Tracks_ could still be used (based upon version _Google's MyTracks_ version 2.0.6). diff --git a/src/main/java/de/dennisguse/opentracks/io/file/exporter/SaveAsyncTask.java b/src/main/java/de/dennisguse/opentracks/io/file/exporter/SaveAsyncTask.java index c1b866ed7..d3d3b2bd1 100644 --- a/src/main/java/de/dennisguse/opentracks/io/file/exporter/SaveAsyncTask.java +++ b/src/main/java/de/dennisguse/opentracks/io/file/exporter/SaveAsyncTask.java @@ -197,9 +197,8 @@ public class SaveAsyncTask extends AsyncTask { String fileName = FileUtils.buildUniqueFileName(directory, track.getName(), extension); File file = new File(directory, fileName); - FileOutputStream fileOutputStream = null; - try { - fileOutputStream = new FileOutputStream(file); + + try (FileOutputStream fileOutputStream = new FileOutputStream(file)) { if (trackExporter.writeTrack(fileOutputStream)) { savedPath = file.getAbsolutePath(); return true; @@ -213,14 +212,9 @@ public class SaveAsyncTask extends AsyncTask { } catch (FileNotFoundException e) { Log.e(TAG, "Unable to open file " + file.getName(), e); return false; - } finally { - if (fileOutputStream != null) { - try { - fileOutputStream.close(); - } catch (IOException e) { - Log.e(TAG, "Unable to close file output stream", e); - } - } + } catch (IOException e) { + Log.e(TAG, "Unable to close file output stream", e); + return false; } }