sonar issue fix blocker, critical 39/56839/4
authorArindam Mondal <arind.mondal@samsung.com>
Thu, 19 Jul 2018 06:36:46 +0000 (15:36 +0900)
committerTal Gitelman <tg851x@intl.att.com>
Wed, 1 Aug 2018 14:48:00 +0000 (14:48 +0000)
Issue-ID: SDC-1534

Change-Id: I58ae2497568fbdff58a1928bdc1e7187be9f0632
Signed-off-by: Arindam Mondal <arind.mondal@samsung.com>
asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/DataMigration.java
asdctool/src/main/java/org/openecomp/sdc/asdctool/main/SdcSchemaFileImport.java

index cad7a05..fddcab1 100644 (file)
@@ -718,20 +718,18 @@ public class DataMigration {
         */
        private Map<Table, PrintWriter> createWriters(Map<Table, File> files) {
                Map<Table, PrintWriter> printerWritersMap = new EnumMap<>(Table.class);
-               try {
+      
                        for (Table table : files.keySet()) {
                                log.info("creating writer for {}", table);
                                File file = files.get(table);
-                               FileWriter fw = new FileWriter(file, true);
-                               BufferedWriter bw = new BufferedWriter(fw);
-                               PrintWriter out = new PrintWriter(bw);
+                try(PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(file)) )){
                                printerWritersMap.put(table, out);
                                log.info("creating writer for {} was successful", table);
-                       }
-               } catch (IOException e) {
-                       log.error("create writer to file failed", e);
-                       return null;
-               }
+            } catch (IOException e) {
+               log.error("create writer to file failed",e);
+               return null;
+                       } 
+        } 
                return printerWritersMap;
        }
 
index d2fa3a4..5c3c036 100644 (file)
@@ -100,11 +100,10 @@ public class SdcSchemaFileImport {
                //Loop over schema file list and create each yaml file from /import/tosca folder 
                SchemaZipFileEnum[] schemaFileList = SchemaZipFileEnum.values();
                for (SchemaZipFileEnum schemaZipFileEnum : schemaFileList) {
-                       try {
+                       String pathname = importToscaPath + SEPARATOR + schemaZipFileEnum.getSourceFolderName() + SEPARATOR +  schemaZipFileEnum.getSourceFileName() + YAML_EXTENSION;
+                       try(InputStream input = new FileInputStream(new File(pathname));) {
                                //get the source yaml file
-                               String pathname = importToscaPath + SEPARATOR + schemaZipFileEnum.getSourceFolderName() + SEPARATOR +  schemaZipFileEnum.getSourceFileName() + YAML_EXTENSION;
                                System.out.println("Processing file "+pathname+"....");
-                               InputStream input = new FileInputStream(new File(pathname));
                                //Convert the content of file to yaml 
                                Yaml yamlFileSource = new Yaml();
                            Object content = yamlFileSource.load(input);