diff options
author | 2017-10-22 19:03:46 +0300 | |
---|---|---|
committer | 2017-10-23 12:38:26 +0300 | |
commit | b118cd814ea0a230486c4179d0bcdc27d39d92b1 (patch) | |
tree | e61517052aab52e3a99e399e979456a2ef60bafd /openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities | |
parent | 30e46525c1406fb3b10603606c4efcc033ee58c4 (diff) |
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 <vitaliy.emporopulo@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities')
-rw-r--r-- | openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java index 6ff213c34c..6ab3f8b049 100644 --- a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java @@ -28,6 +28,7 @@ import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.tosca.services.YamlUtil; import java.io.ByteArrayInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.net.URL; @@ -54,7 +55,16 @@ public class FileUtils { * @param function logic to be applied to the input stream */ public static <T> T readViaInputStream(String fileName, Function<InputStream, T> function) { - return readViaInputStream(FileUtils.class.getClassLoader().getResource(fileName), function); + + Objects.requireNonNull(fileName); + + // the leading slash doesn't make sense and doesn't work when used with a class loader + URL resource = FileUtils.class.getClassLoader().getResource(fileName.startsWith("/") ? fileName.substring(1) : fileName); + if (resource == null) { + throw new IllegalArgumentException("Resource not found: " + fileName); + } + + return readViaInputStream(resource, function); } /** |