[Android] Ensure streams are closed
Geoffrey Métais
git at videolan.org
Tue Feb 17 17:43:49 CET 2015
vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Feb 17 17:21:59 2015 +0100| [fe4d8405e6dba24edb74a8160cf572c55b317be2] | committer: Geoffrey Métais
Ensure streams are closed
CID #1226312, #1226311
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=fe4d8405e6dba24edb74a8160cf572c55b317be2
---
.../src/org/videolan/vlc/gui/video/VideoPlayerActivity.java | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index d427bc5..556f1d2 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -2267,6 +2267,8 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
// Mail-based apps - download the stream to a temporary file and play it
if(data.getHost().equals("com.fsck.k9.attachmentprovider")
|| data.getHost().equals("gmail-ls")) {
+ InputStream is = null;
+ OutputStream os = null;
try {
Cursor cursor = getContentResolver().query(data,
new String[]{MediaStore.MediaColumns.DISPLAY_NAME}, null, null, null);
@@ -2276,20 +2278,21 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
cursor.close();
Log.i(TAG, "Getting file " + filename + " from content:// URI");
- InputStream is = getContentResolver().openInputStream(data);
- OutputStream os = new FileOutputStream(Environment.getExternalStorageDirectory().getPath() + "/Download/" + filename);
+ is = getContentResolver().openInputStream(data);
+ os = new FileOutputStream(Environment.getExternalStorageDirectory().getPath() + "/Download/" + filename);
byte[] buffer = new byte[1024];
int bytesRead = 0;
while((bytesRead = is.read(buffer)) >= 0) {
os.write(buffer, 0, bytesRead);
}
- os.close();
- is.close();
mLocation = LibVLC.PathToURI(Environment.getExternalStorageDirectory().getPath() + "/Download/" + filename);
}
} catch (Exception e) {
Log.e(TAG, "Couldn't download file from mail URI");
encounteredError();
+ } finally {
+ Util.close(is);
+ Util.close(os);
}
}
// Media or MMS URI
More information about the Android
mailing list