- Properties pp = new Properties();
- InputStream in = new FileInputStream(fileName);
- pp.load(in);
- for (Object key : pp.keySet()) {
- String pfx = contextPrefix != null ? contextPrefix + '.' : "";
- String name = (String) key;
- String value = pp.getProperty(name);
- if (value != null && value.trim().length() > 0) {
- ctx.setAttribute(pfx + name, value.trim());
- log.info("+++ " + pfx + name + ": [" + value + "]");
+ File file = new File(param.fileName);
+ 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()) + "]");
+ }
+ }
+ } 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) + "]");
+ }
+ }