- 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, getObfuscatedVal(value.trim()));
+ log.info("+++ " + pfx + name + ": [" + maskPassword(pfx + name, value) + "]");
+ }
+ }
+ }
+ if (mm != null) {
+ for (Map.Entry<String, String> entry : mm.entrySet()) {
+ ctx.setAttribute(pfx + entry.getKey(), getObfuscatedVal(entry.getValue()));
+ log.info("+++ " + pfx + entry.getKey() + ": ["
+ + maskPassword(pfx + entry.getKey(), entry.getValue()) + "]");
+ }
+ }