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();
}
+ 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)
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
}
}
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;