[Android] Close streams
Geoffrey Métais
git at videolan.org
Tue Feb 17 17:43:46 CET 2015
vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Feb 17 11:56:03 2015 +0100| [2718a42c23627ca071a1118a32a2be1b3e22c210] | committer: Geoffrey Métais
Close streams
CID #1226314
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=2718a42c23627ca071a1118a32a2be1b3e22c210
---
vlc-android/src/org/videolan/vlc/util/Util.java | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/util/Util.java b/vlc-android/src/org/videolan/vlc/util/Util.java
index caf821b..28f0cc8 100644
--- a/vlc-android/src/org/videolan/vlc/util/Util.java
+++ b/vlc-android/src/org/videolan/vlc/util/Util.java
@@ -21,6 +21,7 @@
package org.videolan.vlc.util;
import java.io.BufferedReader;
+import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -78,9 +79,11 @@ public class Util {
}
public static String readAsset(String assetName, String defaultS) {
+ InputStream is = null;
+ BufferedReader r = null;
try {
- InputStream is = VLCApplication.getAppResources().getAssets().open(assetName);
- BufferedReader r = new BufferedReader(new InputStreamReader(is, "UTF8"));
+ is = VLCApplication.getAppResources().getAssets().open(assetName);
+ r = new BufferedReader(new InputStreamReader(is, "UTF8"));
StringBuilder sb = new StringBuilder();
String line = r.readLine();
if(line != null) {
@@ -95,6 +98,9 @@ public class Util {
return sb.toString();
} catch (IOException e) {
return defaultS;
+ } finally {
+ close(is);
+ close(r);
}
}
@@ -274,4 +280,11 @@ public class Util {
}
return deleted;
}
+
+ public static void close(Closeable closeable) {
+ try {
+ closeable.close();
+ } catch (IOException e) {}
+ catch (NullPointerException e) {}
+ }
}
More information about the Android
mailing list