From c3fd2d7cdd80d40c8485a29125f0f3d335aad480 Mon Sep 17 00:00:00 2001 From: Arindam Mondal Date: Thu, 19 Jul 2018 15:36:46 +0900 Subject: sonar issue fix blocker, critical Issue-ID: SDC-1534 Change-Id: I58ae2497568fbdff58a1928bdc1e7187be9f0632 Signed-off-by: Arindam Mondal --- .../org/openecomp/sdc/asdctool/impl/DataMigration.java | 16 +++++++--------- .../openecomp/sdc/asdctool/main/SdcSchemaFileImport.java | 5 ++--- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/DataMigration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/DataMigration.java index cad7a05cb2..fddcab1e9f 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/DataMigration.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/DataMigration.java @@ -718,20 +718,18 @@ public class DataMigration { */ private Map createWriters(Map files) { Map 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; } diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/SdcSchemaFileImport.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/SdcSchemaFileImport.java index d2fa3a41fc..5c3c0361a3 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/SdcSchemaFileImport.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/SdcSchemaFileImport.java @@ -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); -- cgit 1.2.3-korg