aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/persistance
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2017-10-06 22:35:34 +0200
committerChristian Schneppe <christian@pix-art.de>2017-10-06 22:35:34 +0200
commit21f167a9129900f09ebc7b29f8d1e5522796fa82 (patch)
treea180f4de6c05d082192ea32343adc7bce3b2eab4 /src/main/java/de/pixart/messenger/persistance
parent9b2fab93f3c26a3f602faed0b48f577af32c07ae (diff)
FileBackend: close cursor after retrieving file size
Diffstat (limited to 'src/main/java/de/pixart/messenger/persistance')
-rw-r--r--src/main/java/de/pixart/messenger/persistance/FileBackend.java18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/main/java/de/pixart/messenger/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java
index 727892af0..350dfb7c9 100644
--- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java
+++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java
@@ -149,17 +149,17 @@ public class FileBackend {
}
private static long getFileSize(Context context, Uri uri) {
- Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
- if (cursor != null && cursor.moveToFirst()) {
- long size = cursor.getLong(cursor.getColumnIndex(OpenableColumns.SIZE));
- cursor.close();
- return size;
- } else {
- if (cursor != null) {
+ try {
+ final Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
+ if (cursor != null && cursor.moveToFirst()) {
+ long size = cursor.getLong(cursor.getColumnIndex(OpenableColumns.SIZE));
cursor.close();
+ return size;
+ } else {
+ return -1;
}
- File f = new File(uri.getPath());
- return f.length();
+ } catch (Exception e) {
+ return -1;
}
}