浏览代码

providers: Close and flush FileOutputStream using try-with-resources to avoid memleak.

eho 7 年之前
父节点
当前提交
7c28ca2022
共有 1 个文件被更改,包括 2 次插入6 次删除
  1. 2 6
      src/main/java/com/owncloud/android/providers/DiskLruImageCacheFileProvider.java

+ 2 - 6
src/main/java/com/owncloud/android/providers/DiskLruImageCacheFileProvider.java

@@ -89,15 +89,11 @@ public class DiskLruImageCacheFileProvider extends ContentProvider {
             byte[] bitmapData = bos.toByteArray();
 
             //write the bytes in file
-            FileOutputStream fos = null;
-            try {
-                fos = new FileOutputStream(f);
+            try (FileOutputStream fos = new FileOutputStream(f)){
+                fos.write(bitmapData);
             } catch (FileNotFoundException e) {
                 Log_OC.e(TAG, "File not found: " + e.getMessage());
             }
-            fos.write(bitmapData);
-            fos.flush();
-            fos.close();
 
         } catch (Exception e) {
             Log_OC.e(TAG, "Error opening file: " + e.getMessage());