sonar fix: Resrc handling AdapterResourceManager 09/35209/1
authorajay priyadarshi <ajay.priyadarshi@ril.com>
Mon, 12 Mar 2018 12:23:11 +0000 (17:53 +0530)
committerajay priyadarshi <ajay.priyadarshi@ril.com>
Mon, 12 Mar 2018 12:23:11 +0000 (17:53 +0530)
try-with resource issues fixed
file name: AdapterResourceManager.java

Change-Id: I1d0285803d64a6ae78a6079b4f94c4892baefbce
Issue-ID: VFC-804
Signed-off-by: ajay priyadarshi <ajay.priyadarshi@ril.com>
juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/adapter/impl/AdapterResourceManager.java

index 82dd7ef..2d0bac7 100644 (file)
@@ -101,7 +101,8 @@ public class AdapterResourceManager implements IResourceManager {
                        csarPkgInfo = readCsarPkgInfo();
                csarPkgInfoObj = JSONObject.fromObject(csarPkgInfo); //NOSONAR
                } catch (IOException e) {
-                       e.printStackTrace();
+                       //e.printStackTrace();
+                       LOG.error("csarPkgInfo", e);
                }
                
         String csarfilepath = csarPkgInfoObj.getString("csar_file_path");
@@ -183,17 +184,15 @@ public class AdapterResourceManager implements IResourceManager {
      * @since  NFVO 0.5
      */
     public static String readCsarPkgInfo() throws IOException {
-        InputStream ins = null;
-        BufferedInputStream bins = null;
         String fileContent = "";
 
         String fileName = SystemEnvVariablesFactory.getInstance().getAppRoot() + System.getProperty("file.separator")
                 + "etc" + System.getProperty("file.separator") + "csarInfo" + System.getProperty("file.separator")
                 + Constant.CSARINFO;
 
-        try {
-            ins = new FileInputStream(fileName);
-            bins = new BufferedInputStream(ins);
+        try (
+            InputStream ins = new FileInputStream(fileName);
+            BufferedInputStream bins = new BufferedInputStream(ins)){
 
             byte[] contentByte = new byte[ins.available()];
             int num = bins.read(contentByte);
@@ -203,14 +202,7 @@ public class AdapterResourceManager implements IResourceManager {
             }
         } catch (FileNotFoundException e) {
             LOG.error(fileName + "is not found!", e);
-        } finally {
-            if (ins != null) {
-                ins.close();
-            }
-            if (bins != null) {
-                bins.close();
-            }
-        }
+        } 
         return fileContent;
     }