summaryrefslogtreecommitdiffstats
path: root/sdnr/wt/common/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'sdnr/wt/common/src/main')
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/configuration/ConfigurationFileRepresentation.java31
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/configuration/subtypes/Section.java3
2 files changed, 14 insertions, 20 deletions
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/configuration/ConfigurationFileRepresentation.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/configuration/ConfigurationFileRepresentation.java
index 54a5172a3..9ca985d4d 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/configuration/ConfigurationFileRepresentation.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/configuration/ConfigurationFileRepresentation.java
@@ -49,6 +49,8 @@ public class ConfigurationFileRepresentation implements IConfigChangedListener {
public static final String SECTIONNAME_ROOT = "";
private static final String LR = "\n";
private static final String EMPTY = "";
+
+ private static final String LOG_UNKNWON_CONFIG_SECTION = "Unknown configuration section {}";
// end of constants
// variables
@@ -70,8 +72,12 @@ public class ConfigurationFileRepresentation implements IConfigChangedListener {
if (!this.mFile.createNewFile()) {
LOG.error("Can not create file {}", f.getAbsolutePath());
}
- this.mFile.setReadable(true, false);
- this.mFile.setWritable(true, false);
+ if (!this.mFile.setReadable(true, false)) {
+ LOG.warn("unable to set file as readable");
+ }
+ if (!this.mFile.setWritable(true, false)) {
+ LOG.warn("unable to set file as writable");
+ }
}
reLoad();
@@ -106,9 +112,7 @@ public class ConfigurationFileRepresentation implements IConfigChangedListener {
String curSectionName = SECTIONNAME_ROOT;
Optional<Section> sectionOptional = this.getSection(curSectionName);
Section curSection = sectionOptional.isPresent() ? sectionOptional.get() : this.addSection(curSectionName);
- BufferedReader br = null;
- try {
- br = new BufferedReader(new FileReader(this.mFile));
+ try (BufferedReader br = new BufferedReader(new FileReader(this.mFile))) {
for (String line; (line = br.readLine()) != null;) {
line = line.trim();
if (line.isEmpty()) {
@@ -124,13 +128,6 @@ public class ConfigurationFileRepresentation implements IConfigChangedListener {
} catch (Exception e) {
LOG.info("Problem loading configuration file. {} {}", getMFileName(), e);
- } finally {
- try {
- if (br != null) {
- br.close();
- }
- } catch (IOException e) {
- }
}
LOG.debug("finished loading file");
LOG.debug("start parsing sections");
@@ -164,9 +161,8 @@ public class ConfigurationFileRepresentation implements IConfigChangedListener {
bw.write(String.join(LR, section.toLines()) + LR + LR);
}
}
- bw.close();
} catch (Exception e) {
- LOG.warn("problem saving value: " + e.getMessage());
+ LOG.warn("problem saving value: {}", e.getMessage());
}
}
@@ -194,7 +190,6 @@ public class ConfigurationFileRepresentation implements IConfigChangedListener {
if (this.fileObserver != null) {
this.fileObserver.interrupt();
}
- super.finalize();
}
/*
@@ -206,7 +201,7 @@ public class ConfigurationFileRepresentation implements IConfigChangedListener {
os.get().setProperty(key, value == null ? "null" : value.toString());
save();
} else {
- LOG.info("Unknown configuration section {}", section);
+ LOG.info(LOG_UNKNWON_CONFIG_SECTION, section);
}
}
@@ -215,7 +210,7 @@ public class ConfigurationFileRepresentation implements IConfigChangedListener {
if (os.isPresent()) {
return os.get().getProperty(propertyKey);
} else {
- LOG.debug("Unknown configuration section {}", section);
+ LOG.debug(LOG_UNKNWON_CONFIG_SECTION, section);
return EMPTY;
}
}
@@ -225,7 +220,7 @@ public class ConfigurationFileRepresentation implements IConfigChangedListener {
if (os.isPresent()) {
return os.get().getLong(propertyKey);
} else {
- LOG.debug("Unknown configuration section {}", section);
+ LOG.debug(LOG_UNKNWON_CONFIG_SECTION, section);
return Optional.empty();
}
}
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/configuration/subtypes/Section.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/configuration/subtypes/Section.java
index c6b121ae3..55e329ebc 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/configuration/subtypes/Section.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/configuration/subtypes/Section.java
@@ -29,7 +29,6 @@ import java.util.Objects;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.eclipse.jdt.annotation.NonNull;
import org.onap.ccsdk.features.sdnr.wt.common.configuration.exception.ConversionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -266,7 +265,7 @@ public class Section {
}
// static methods
- public static void setEnvGetter(@NonNull EnvGetter newEnvGetter) {
+ public static void setEnvGetter(EnvGetter newEnvGetter) {
if (Objects.nonNull(newEnvGetter)) {
envGetter = newEnvGetter;
} else {