Forráskód Böngészése

fix all experimental warnings found by findbugs (missing stream closing)

AndyScherzinger 6 éve
szülő
commit
0fb3dedef1

+ 16 - 2
src/gplay/java/com/owncloud/android/utils/PushUtils.java

@@ -298,7 +298,6 @@ public final class PushUtils {
             fileInputStream = new FileInputStream(path);
             byte[] bytes = new byte[fileInputStream.available()];
             fileInputStream.read(bytes);
-            fileInputStream.close();
 
             KeyFactory keyFactory = KeyFactory.getInstance("RSA");
 
@@ -318,6 +317,14 @@ public final class PushUtils {
             Log_OC.d(TAG, "InvalidKeySpecException while reading the key");
         } catch (NoSuchAlgorithmException e) {
             Log_OC.d(TAG, "RSA algorithm not supported");
+        } finally {
+            if (fileInputStream != null) {
+                try {
+                    fileInputStream.close();
+                } catch (IOException e) {
+                    Log_OC.e(TAG, "Error closing input stream during reading key from file", e);
+                }
+            }
         }
 
         return null;
@@ -334,12 +341,19 @@ public final class PushUtils {
             }
             keyFileOutputStream = new FileOutputStream(path);
             keyFileOutputStream.write(encoded);
-            keyFileOutputStream.close();
             return 0;
         } catch (FileNotFoundException e) {
             Log_OC.d(TAG, "Failed to save key to file");
         } catch (IOException e) {
             Log_OC.d(TAG, "Failed to save key to file via IOException");
+        } finally {
+            if (keyFileOutputStream != null) {
+                try {
+                    keyFileOutputStream.close();
+                } catch (IOException e) {
+                    Log_OC.e(TAG, "Error closing input stream during reading key from file", e);
+                }
+            }
         }
 
         return -1;

+ 10 - 1
src/main/java/com/owncloud/android/utils/EncryptionUtils.java

@@ -571,8 +571,9 @@ public final class EncryptionUtils {
      */
 
     public static String getMD5Sum(File file) {
+        FileInputStream fileInputStream = null;
         try {
-            FileInputStream fileInputStream = new FileInputStream(file);
+            fileInputStream = new FileInputStream(file);
             MessageDigest md5 = MessageDigest.getInstance("MD5");
             byte[] bytes = new byte[2048];
             int readBytes;
@@ -585,6 +586,14 @@ public final class EncryptionUtils {
 
         } catch (Exception e) {
             Log_OC.e(TAG, e.getMessage());
+        } finally {
+            if (fileInputStream != null) {
+                try {
+                    fileInputStream.close();
+                } catch (IOException e) {
+                    Log_OC.e(TAG, "Error getting MD5 checksum for file", e);
+                }
+            }
         }
 
         return "";

+ 2 - 0
src/main/java/com/owncloud/android/utils/FileStorageUtils.java

@@ -280,6 +280,8 @@ public final class FileStorageUtils {
         }
     }
 
+    @SuppressFBWarnings(value="OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE",
+            justification="False-positive on the output stream")
     public static boolean copyFile(File src, File target) {
         boolean ret = true;