sonar fix: Resource handling modified 19/35219/1
authorajay priyadarshi <ajay.priyadarshi@ril.com>
Mon, 12 Mar 2018 12:41:30 +0000 (18:11 +0530)
committerajay priyadarshi <ajay.priyadarshi@ril.com>
Mon, 12 Mar 2018 12:41:30 +0000 (18:11 +0530)
try-with resource issues fixed
file name: JujuAdapter2DriverMgrService.java

Change-Id: I82126b1adae3c186bfbf3ce5c17ac8bcb6455449
Issue-ID: VFC-806
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/api/internalsvc/impl/JujuAdapter2DriverMgrService.java

index 7784ba6..12ab241 100644 (file)
@@ -82,17 +82,15 @@ public class JujuAdapter2DriverMgrService implements IJujuAdapter2DriverMgrServi
      * @throws IOException
      */
     public static String readVimAdapterInfoFromJson() throws IOException {
-        InputStream ins = null;
-        BufferedInputStream bins = null;
         String fileContent = "";
 
         String fileName = SystemEnvVariablesFactory.getInstance().getAppRoot() + System.getProperty("file.separator")
                 + "etc" + System.getProperty("file.separator") + "adapterInfo" + System.getProperty("file.separator")
                 + VIMADAPTER2DRIVERMGR;
 
-        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);
@@ -102,14 +100,7 @@ public class JujuAdapter2DriverMgrService implements IJujuAdapter2DriverMgrServi
             }
         } catch(FileNotFoundException e) {
             LOG.error(fileName + "is not found!", e);
-        } finally {
-            if(ins != null) {
-                ins.close();
-            }
-            if(bins != null) {
-                bins.close();
-            }
-        }
+        } 
 
         return fileContent;
     }