diff options
author | Parshad Patel <pars.patel@samsung.com> | 2018-11-05 13:23:21 +0900 |
---|---|---|
committer | Parshad Patel <pars.patel@samsung.com> | 2018-11-05 13:23:34 +0900 |
commit | fcb76a5d9f223831c2ec2012b7dd26aac53152a3 (patch) | |
tree | ee9ceb09865533936c6f2ea1c28b51752479909b /properties-node/provider/src/main | |
parent | 69d612621915cf9793b5e8c5a4e9ec42187a557d (diff) |
Fix sonar blocker issue in sli/plugins
Fix use try with resources issue in PropertiesNode.java
Issue-ID: CCSDK-647
Change-Id: I62f2c0ecae65efb9d53022518fe36931ba5991e3
Signed-off-by: Parshad Patel <pars.patel@samsung.com>
Diffstat (limited to 'properties-node/provider/src/main')
-rw-r--r-- | properties-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/prop/PropertiesNode.java | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/properties-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/prop/PropertiesNode.java b/properties-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/prop/PropertiesNode.java index cefc9c23e..612592b58 100644 --- a/properties-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/prop/PropertiesNode.java +++ b/properties-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/prop/PropertiesNode.java @@ -45,19 +45,36 @@ public class PropertiesNode implements SvcLogicJavaPlugin { Properties prop = new Properties(); try { File file = new File(param.fileName); - InputStream in = new FileInputStream(file); - Map<String, String> mm = null; - String pfx = param.contextPrefix != null ? param.contextPrefix + '.' : ""; - if(param.fileBasedParsing){ - byte[] data = new byte[(int) file.length()]; - if ("json".equalsIgnoreCase(getFileExtension(param.fileName))) { - in.read(data); - String str = new String(data, "UTF-8"); - mm = JsonParser.convertToProperties(str); - } else if ("xml".equalsIgnoreCase(getFileExtension(param.fileName))) { - in.read(data); - String str = new String(data, "UTF-8"); - mm = XmlParser.convertToProperties(str, param.listNameList); + try(InputStream in = new FileInputStream(file)){ + Map<String, String> mm = null; + String pfx = param.contextPrefix != null ? param.contextPrefix + '.' : ""; + if(param.fileBasedParsing){ + byte[] data = new byte[(int) file.length()]; + if ("json".equalsIgnoreCase(getFileExtension(param.fileName))) { + in.read(data); + String str = new String(data, "UTF-8"); + mm = JsonParser.convertToProperties(str); + } else if ("xml".equalsIgnoreCase(getFileExtension(param.fileName))) { + in.read(data); + String str = new String(data, "UTF-8"); + mm = XmlParser.convertToProperties(str, param.listNameList); + } else { + prop.load(in); + for (Object key : prop.keySet()) { + String name = (String) key; + String value = prop.getProperty(name); + if (value != null && value.trim().length() > 0) { + ctx.setAttribute(pfx + name, value.trim()); + log.info("+++ " + pfx + name + ": [" + value + "]"); + } + } + } + if (mm != null){ + for (Map.Entry<String,String> entry : mm.entrySet()){ + ctx.setAttribute(pfx + entry.getKey(), entry.getValue()); + log.info("+++ " + pfx + entry.getKey() + ": [" + entry.getValue() + "]"); + } + } } else { prop.load(in); for (Object key : prop.keySet()) { @@ -69,24 +86,7 @@ public class PropertiesNode implements SvcLogicJavaPlugin { } } } - if (mm != null){ - for (Map.Entry<String,String> entry : mm.entrySet()){ - ctx.setAttribute(pfx + entry.getKey(), entry.getValue()); - log.info("+++ " + pfx + entry.getKey() + ": [" + entry.getValue() + "]"); - } - } - } else { - prop.load(in); - for (Object key : prop.keySet()) { - String name = (String) key; - String value = prop.getProperty(name); - if (value != null && value.trim().length() > 0) { - ctx.setAttribute(pfx + name, value.trim()); - log.info("+++ " + pfx + name + ": [" + value + "]"); - } - } } - in.close(); } catch (IOException e) { throw new SvcLogicException("Cannot read property file: " + param.fileName + ": " + e.getMessage(), e); } |