From b118cd814ea0a230486c4179d0bcdc27d39d92b1 Mon Sep 17 00:00:00 2001 From: vempo Date: Sun, 22 Oct 2017 19:03:46 +0300 Subject: Additinal fixes for resources not being released More fixes for input streams not being properly closed, with unit tests and other minor improvements (code cleanup and coding conventions). Change-Id: I6751f924a1469d49b996e4f1d6c61371af6714b1 Issue-ID: SDC-291 Signed-off-by: vempo --- .../openecomp/sdc/validation/util/ValidationTestUtil.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main') diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/util/ValidationTestUtil.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/util/ValidationTestUtil.java index fa1946f987..2b58a30e50 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/util/ValidationTestUtil.java +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/util/ValidationTestUtil.java @@ -25,6 +25,7 @@ import org.testng.Assert; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.StringWriter; import java.net.URL; @@ -55,8 +56,6 @@ public class ValidationTestUtil { private static Map getContentMapByPath(String path) { Map contentMap = new HashMap<>(); - byte[] fileContent; - FileInputStream fis; URL url = ValidationTestUtil.class.getResource(path); File pathFile = new File(url.getFile()); File[] files; @@ -71,13 +70,13 @@ public class ValidationTestUtil { } for (File file : files) { - try { - fis = new FileInputStream(file); - fileContent = FileUtils.toByteArray(fis); - contentMap.put(file.getName(), fileContent); + + try (FileInputStream fis = new FileInputStream(file)) { + contentMap.put(file.getName(), FileUtils.toByteArray(fis)); } catch (IOException e) { - log.debug("",e); + throw new RuntimeException("Failed to read file: " + file, e); } + } return contentMap; } -- cgit 1.2.3-korg