aboutsummaryrefslogtreecommitdiffstats
path: root/ONAP-PAP-REST/src/main/java
diff options
context:
space:
mode:
authorSP00501638 <SP00501638@techmahindra.com>2018-03-13 12:13:15 +0530
committerSP00501638 <SP00501638@techmahindra.com>2018-03-13 12:13:40 +0530
commit29d561f52c1b99bce44aba0894e9661be3168779 (patch)
tree0b3349315d109a07bf649a9c0d327e0c0f24ab9e /ONAP-PAP-REST/src/main/java
parentcbd2227c7b6adfa878eb97b6f6a85b73bf1d1a75 (diff)
Sonar Blocker
Use try-with-resources or close this BufferedWriter in a finally clause FirewallConfigPolicy.java:107 Sonar Link: https://sonar.onap.org/project/issues?id=org.onap.policy.engine%3APolicyEngineSuite&myIssues=true&open=AWF91ixe8TZzbCgU6ar2&resolved=false&severities=BLOCKER Location: ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicy.java Change-Id: I0ab8bf61fb9a6eb32ebdb5fccb66a67a8ac36b77 Issue-ID: POLICY-687 Signed-off-by: SP00501638 <SP00501638@techmahindra.com>
Diffstat (limited to 'ONAP-PAP-REST/src/main/java')
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicy.java29
1 files changed, 9 insertions, 20 deletions
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicy.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicy.java
index d95b36709..6e46ab1c0 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicy.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicy.java
@@ -98,32 +98,21 @@ public class FirewallConfigPolicy extends Policy {
// Saving the Configurations file at server location for config policy.
protected void saveConfigurations(String policyName, String jsonBody) {
String configurationName = policyName;
- FileWriter fw = null;
- try{
- if(configurationName.endsWith(".xml")){
- configurationName = configurationName.replace(".xml", "");
- }
- fw = new FileWriter(CONFIG_HOME + File.separator + configurationName + ".json");
- BufferedWriter bw = new BufferedWriter(fw);
- bw.write(jsonBody);
- bw.close();
+ if(configurationName.endsWith(".xml")){
+ configurationName = configurationName.replace(".xml", "");
+ }
+ String fileName = CONFIG_HOME + File.separator + configurationName + ".json";
+ try(BufferedWriter bw = new BufferedWriter(new FileWriter(fileName))){
+ bw.write(jsonBody);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Configuration is succesfully saved");
}
} catch (IOException e) {
- LOGGER.error("Exception Occured"+e);
- }finally{
- try{
- if(fw != null){
- fw.close();
- }
- }catch(Exception e){
- LOGGER.error("Exception Occured"+e);
- }
+ LOGGER.error("Save of configuration to file" +fileName+ "failed",e);
}
}
-
- //Utility to read json data from the existing file to a string
+
+ //Utility to read json data from the existing file to a string
static String readFile(String path, Charset encoding) throws IOException {
byte[] encoded = Files.readAllBytes(Paths.get(path));
return new String(encoded, encoding);