[Android] Properly close streams

Geoffrey Métais git at videolan.org
Tue Feb 17 17:43:48 CET 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Feb 17 15:30:28 2015 +0100| [d30f8ee6aa9f71054f542ac5434bbe712e78fc60] | committer: Geoffrey Métais

Properly close streams

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=d30f8ee6aa9f71054f542ac5434bbe712e78fc60
---

 vlc-android/src/org/videolan/vlc/util/Logcat.java |   12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/util/Logcat.java b/vlc-android/src/org/videolan/vlc/util/Logcat.java
index 09f67d4..8c299bb 100644
--- a/vlc-android/src/org/videolan/vlc/util/Logcat.java
+++ b/vlc-android/src/org/videolan/vlc/util/Logcat.java
@@ -45,24 +45,26 @@ public class Logcat implements Runnable {
     @Override
     public void run() {
         final String[] args = { "logcat", "-v", "time" };
-
+        InputStreamReader input = null;
+        BufferedReader br = null;
         try {
             synchronized (this) {
                 if (!mRun)
                     return;
                 mProcess = Runtime.getRuntime().exec(args);
             }
-            InputStreamReader input = new InputStreamReader(
+            input = new InputStreamReader(
                     mProcess.getInputStream());
-            BufferedReader br = new BufferedReader(input);
+            br = new BufferedReader(input);
             String line;
 
             while ((line = br.readLine()) != null)
                 mCallback.onLog(line);
 
-            br.close();
-            input.close();
         } catch (IOException e) {
+        } finally {
+            Util.close(input);
+            Util.close(br);
         }
     }
 



More information about the Android mailing list