sonar fix: Resource handling in YamlUtil 07/35207/1
authorajay priyadarshi <ajay.priyadarshi@ril.com>
Mon, 12 Mar 2018 12:04:33 +0000 (17:34 +0530)
committerajay priyadarshi <ajay.priyadarshi@ril.com>
Mon, 12 Mar 2018 12:04:33 +0000 (17:34 +0530)
try-with resource & logging issues fixed
file name: YamlUtil.java

Change-Id: Ib3ad9afad0b11ce3ba8bf3805c55a4247f86cc0e
Issue-ID: VFC-803
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/common/YamlUtil.java

index a1071f1..a32aad5 100644 (file)
@@ -116,10 +116,12 @@ public class YamlUtil {
         name.put("default","hello,it's me");
 //      new Yaml().dump(config, new FileWriter("C:\\Users\\z00292420\\Desktop\\juju\\config2.yaml"));
         String newYaml = new Yaml().dumpAsMap(config);
-        Writer w = new FileWriter(new File("C:\\Users\\z00292420\\Desktop\\juju"));
+        try(Writer w = new FileWriter(new File("C:\\Users\\z00292420\\Desktop\\juju"))){
         w.write(newYaml);
-        w.flush();
-        w.close();
-        System.out.println(newYaml);
+       }catch(Exception e){
+        log.error("Write Yaml Error: ",e);
+               throw new IOException("Write Yaml Error" + e);
+       }
+        //System.out.println(newYaml);
     }
 }