Policy:Blocker 93/33393/4
authorManamohan Satapathy <MS00534989@techmahindra.com>
Thu, 8 Mar 2018 06:51:51 +0000 (12:21 +0530)
committerManamohan Satapathy <MS00534989@techmahindra.com>
Thu, 8 Mar 2018 06:52:15 +0000 (12:22 +0530)
Use try-with-resources or close this FileOutputStream in a finally clause.:L574 L575
Issue-ID: POLICY-656

Link: https://sonar.onap.org/issues?myIssues=true&resolved=false
Location:BRMSGateway\src\main\java\org\onap\policy\brmsInterface\BRMSPush.java

Change-Id: Id9ce5e5505bb3c622652cd7ff1e844519c9c786f
Signed-off-by: Manamohan Satapathy <MS00534989@techmahindra.com>
BRMSGateway/src/main/java/org/onap/policy/brmsInterface/BRMSPush.java

index b76812b..fd864fd 100644 (file)
@@ -571,14 +571,17 @@ public class BRMSPush {
         String fileName = "rule.jar";
         try {
             website = new URL(artifact.getResourceURI());
-            ReadableByteChannel rbc = Channels.newChannel(website.openStream());
-            FileOutputStream fos = new FileOutputStream(fileName);
-            fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
-            fos.close();
-            extractJar(fileName, dirName);
-            new File(fileName).delete();
-        } catch (IOException e) {
-            LOGGER.error("Error while downloading the project to File System. " + e.getMessage(), e);
+            try( ReadableByteChannel rbc = Channels.newChannel(website.openStream());
+                       FileOutputStream fos = new FileOutputStream(fileName)){
+               fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
+                extractJar(fileName, dirName);
+                new File(fileName).delete();
+            }catch (IOException e) {
+         LOGGER.error("Error while downloading the project to File System. " + e.getMessage(), e);
+                       }
+          
+        } catch (IOException e1) {
+            LOGGER.error("Error while retrieve the artifact. " + e1.getMessage(), e1);
         }
     }