summaryrefslogtreecommitdiffstats
path: root/aai-core/src/main/java
diff options
context:
space:
mode:
authorVenkata Harish Kajur <vk250x@att.com>2018-07-23 13:17:44 +0000
committerGerrit Code Review <gerrit@onap.org>2018-07-23 13:17:44 +0000
commit6b007f7277b1188627388f54cd1cc5f80743a071 (patch)
treea5a9c723dfa2d8d2a687040d385d9e79b6245f18 /aai-core/src/main/java
parentdd29b7fa91d835a29b62e078a53bc82a6d0c4c10 (diff)
parent825208513498704df4c076d9e5918e2022a56443 (diff)
Merge "Fix stream closing"
Diffstat (limited to 'aai-core/src/main/java')
-rw-r--r--aai-core/src/main/java/org/onap/aai/restcore/util/GenerateEdgeRules.java54
-rw-r--r--aai-core/src/main/java/org/onap/aai/util/AAIConfig.java3
-rw-r--r--aai-core/src/main/java/org/onap/aai/util/HttpsAuthExternalClient.java11
-rw-r--r--aai-core/src/main/java/org/onap/aai/util/genxsd/PutRelationPathSet.java17
-rw-r--r--aai-core/src/main/java/org/onap/aai/util/genxsd/YAMLfromOXM.java10
5 files changed, 35 insertions, 60 deletions
diff --git a/aai-core/src/main/java/org/onap/aai/restcore/util/GenerateEdgeRules.java b/aai-core/src/main/java/org/onap/aai/restcore/util/GenerateEdgeRules.java
index afbcf337..4884f400 100644
--- a/aai-core/src/main/java/org/onap/aai/restcore/util/GenerateEdgeRules.java
+++ b/aai-core/src/main/java/org/onap/aai/restcore/util/GenerateEdgeRules.java
@@ -140,42 +140,13 @@ public class GenerateEdgeRules {
Configuration configuration = new Configuration();
Template template = configuration.getTemplate("src/main/resources/edgerulesTemplate.ftlh");
- Writer file = new FileWriter(new File("src/main/resources/EdgeRulesWithNewLabels_v12.json"));
- Map<String, List<EdgeRuleBean>> wrappedRules = new HashMap<>();
- wrappedRules.put("wrappedRules", rulesToWriteV12);
- template.process(wrappedRules, file);
- file.close();
-
- file = new FileWriter(new File("src/main/resources/EdgeRulesWithNewLabels_v7.json"));
- wrappedRules = new HashMap<>();
- wrappedRules.put("wrappedRules", rulesToWriteV7);
- template.process(wrappedRules, file);
- file.close();
-
- file = new FileWriter(new File("src/main/resources/EdgeRulesWithNewLabels_v8.json"));
- wrappedRules = new HashMap<>();
- wrappedRules.put("wrappedRules", rulesToWriteV8);
- template.process(wrappedRules, file);
- file.close();
-
-
- file = new FileWriter(new File("src/main/resources/EdgeRulesWithNewLabels_v9.json"));
- wrappedRules = new HashMap<>();
- wrappedRules.put("wrappedRules", rulesToWriteV9);
- template.process(wrappedRules, file);
- file.close();
-
- file = new FileWriter(new File("src/main/resources/EdgeRulesWithNewLabels_v10.json"));
- wrappedRules = new HashMap<>();
- wrappedRules.put("wrappedRules", rulesToWriteV10);
- template.process(wrappedRules, file);
- file.close();
-
- file = new FileWriter(new File("src/main/resources/EdgeRulesWithNewLabels_v11.json"));
- wrappedRules = new HashMap<>();
- wrappedRules.put("wrappedRules", rulesToWriteV11);
- template.process(wrappedRules, file);
- file.close();
+
+ saveRulesIntoTheFile("src/main/resources/EdgeRulesWithNewLabels_v12.json", template, rulesToWriteV12);
+ saveRulesIntoTheFile("src/main/resources/EdgeRulesWithNewLabels_v7.json", template, rulesToWriteV7);
+ saveRulesIntoTheFile("src/main/resources/EdgeRulesWithNewLabels_v8.json", template, rulesToWriteV8);
+ saveRulesIntoTheFile("src/main/resources/EdgeRulesWithNewLabels_v9.json", template, rulesToWriteV9);
+ saveRulesIntoTheFile("src/main/resources/EdgeRulesWithNewLabels_v10.json", template, rulesToWriteV10);
+ saveRulesIntoTheFile("src/main/resources/EdgeRulesWithNewLabels_v11.json", template, rulesToWriteV11);
} catch(Exception ex){
ex.printStackTrace();
@@ -184,6 +155,17 @@ public class GenerateEdgeRules {
}
+ private static void saveRulesIntoTheFile(String filePath, Template fileTemplate, List<EdgeRuleBean> rulesToWrite)
+ throws IOException, TemplateException {
+
+
+ try (Writer file = new FileWriter(new File(filePath))) {
+ Map<String, List<EdgeRuleBean>> wrappedRules = new HashMap<>();
+ wrappedRules.put("wrappedRules", rulesToWrite);
+ fileTemplate.process(wrappedRules, file);
+ }
+ }
+
private static Map<String, Integer> retrieveHeaderMap(String line){
if(line == null)
diff --git a/aai-core/src/main/java/org/onap/aai/util/AAIConfig.java b/aai-core/src/main/java/org/onap/aai/util/AAIConfig.java
index d1b21634..505e9940 100644
--- a/aai-core/src/main/java/org/onap/aai/util/AAIConfig.java
+++ b/aai-core/src/main/java/org/onap/aai/util/AAIConfig.java
@@ -143,8 +143,7 @@ public class AAIConfig {
LOGGER.debug("Reloading config from " + propFileName);
- try {
- InputStream is = new FileInputStream(propFileName);
+ try(InputStream is = new FileInputStream(propFileName)){
newServerProps = new Properties();
newServerProps.load(is);
propsInitialized = true;
diff --git a/aai-core/src/main/java/org/onap/aai/util/HttpsAuthExternalClient.java b/aai-core/src/main/java/org/onap/aai/util/HttpsAuthExternalClient.java
index 84aa6903..888b04f2 100644
--- a/aai-core/src/main/java/org/onap/aai/util/HttpsAuthExternalClient.java
+++ b/aai-core/src/main/java/org/onap/aai/util/HttpsAuthExternalClient.java
@@ -119,11 +119,12 @@ public class HttpsAuthExternalClient {
String alg = TrustManagerFactory.getDefaultAlgorithm();
TrustManagerFactory tmf = TrustManagerFactory.getInstance(alg);
- FileInputStream tin = new FileInputStream(truststore_path);
- KeyStore ts = KeyStore.getInstance("PKCS12");
- char[] tpwd = truststore_password.toCharArray();
- ts.load(tin, tpwd);
- tmf.init(ts);
+ try(FileInputStream tin = new FileInputStream(truststore_path)) {
+ KeyStore ts = KeyStore.getInstance("PKCS12");
+ char[] tpwd = truststore_password.toCharArray();
+ ts.load(tin, tpwd);
+ tmf.init(ts);
+ }
//ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
// Updating key manager to null, to disable two way SSL
diff --git a/aai-core/src/main/java/org/onap/aai/util/genxsd/PutRelationPathSet.java b/aai-core/src/main/java/org/onap/aai/util/genxsd/PutRelationPathSet.java
index 3e411946..ca5a6fa7 100644
--- a/aai-core/src/main/java/org/onap/aai/util/genxsd/PutRelationPathSet.java
+++ b/aai-core/src/main/java/org/onap/aai/util/genxsd/PutRelationPathSet.java
@@ -117,26 +117,25 @@ public class PutRelationPathSet {
}
}
private void writeRelationsFile() {
- File examplefilePath = new File(GenerateXsd.getYamlDir() + "/relations/" + version.name()+"/"+opId.replace("RelationshipListRelationship", "") + ".json");
- logger.debug(String.join("exampleFilePath: ", examplefilePath.toString()));
- FileOutputStream fop = null;
+ File exampleFilePath = new File(GenerateXsd.getYamlDir() + "/relations/" + version.name()+"/"+opId.replace("RelationshipListRelationship", "") + ".json");
+ logger.debug(String.join("exampleFilePath: ", exampleFilePath.toString()));
+
try {
- if (!examplefilePath.exists()) {
- examplefilePath.getParentFile().mkdirs();
- examplefilePath.createNewFile();
+ if (!exampleFilePath.exists()) {
+ exampleFilePath.getParentFile().mkdirs();
+ exampleFilePath.createNewFile();
}
- fop = new FileOutputStream(examplefilePath);
} catch(Exception e) {
e.printStackTrace();
return;
}
- try {
+
+ try(FileOutputStream fop = new FileOutputStream(exampleFilePath)){
if(relations.size() > 0) {fop.write("[\n".getBytes());}
fop.write(String.join(",\n", relations).getBytes());
if(relations.size() > 0) {fop.write("\n]\n".getBytes());}
fop.flush();
- fop.close();
} catch (Exception e) {
e.printStackTrace();
return;
diff --git a/aai-core/src/main/java/org/onap/aai/util/genxsd/YAMLfromOXM.java b/aai-core/src/main/java/org/onap/aai/util/genxsd/YAMLfromOXM.java
index ce5406a6..da3855c3 100644
--- a/aai-core/src/main/java/org/onap/aai/util/genxsd/YAMLfromOXM.java
+++ b/aai-core/src/main/java/org/onap/aai/util/genxsd/YAMLfromOXM.java
@@ -447,15 +447,9 @@ public class YAMLfromOXM extends OxmFileProcessor {
logger.error( "Exception creating output file " + outfileName);
e.printStackTrace();
}
- BufferedWriter bw = null;
- try {
- Charset charset = Charset.forName("UTF-8");
- Path path = Paths.get(outfileName);
- bw = Files.newBufferedWriter(path, charset);
+
+ try(BufferedWriter bw = Files.newBufferedWriter(Paths.get(outfileName), Charset.forName("UTF-8"))){
bw.write(fileContent);
- if ( bw != null ) {
- bw.close();
- }
} catch ( IOException e) {
logger.error( "Exception writing output file " + outfileName);
e.printStackTrace();