diff --git a/src/main/java/com/iota/iri/IRI.java b/src/main/java/com/iota/iri/IRI.java
index cb03cc19c2..0f8cac9de8 100644
--- a/src/main/java/com/iota/iri/IRI.java
+++ b/src/main/java/com/iota/iri/IRI.java
@@ -34,7 +34,7 @@
* IRI implements all the core functionality necessary for participating in an IOTA network as a full node.
* This includes, but is not limited to:
*
- * - Receiving and broadcasting transactions through TCP and UDP.
+ * - Receiving and broadcasting transactions through TCP
* - Handling of HTTP requests from clients.
* - Tracking and validating Milestones.
* - Loading custom modules that extend the API.
diff --git a/src/main/java/com/iota/iri/IXI.java b/src/main/java/com/iota/iri/IXI.java
index 05d4f3c79a..a1b7ccbf70 100644
--- a/src/main/java/com/iota/iri/IXI.java
+++ b/src/main/java/com/iota/iri/IXI.java
@@ -211,19 +211,14 @@ private void loadModule(Path modulePath) {
return;
}
Map packageJson;
- Reader packageJsonReader;
- try {
- packageJsonReader = new FileReader(packageJsonPath.toFile());
+
+ try (Reader packageJsonReader = new FileReader(packageJsonPath.toFile()) ){
packageJson = gson.fromJson(packageJsonReader, Map.class);
- } catch (FileNotFoundException e) {
+ } catch (IOException e) {
log.error("Could not load {}", packageJsonPath);
return;
}
- try {
- packageJsonReader.close();
- } catch (IOException e) {
- log.error("Could not close file {}", packageJsonPath);
- }
+
if(packageJson != null && packageJson.get("main") != null) {
log.info("Loading module: {}", getModuleName(modulePath, true));
Path pathToMain = Paths.get(modulePath.toString(), (String) packageJson.get("main"));
@@ -242,33 +237,25 @@ private void unloadModule(Path moduleNamePath) {
}
private void attach(Path pathToMain, String moduleName) {
- Reader ixiModuleReader;
- try {
- ixiModuleReader = new FileReader(pathToMain.toFile());
- } catch (FileNotFoundException e) {
- log.error("Could not load {}", pathToMain);
- return;
- }
- log.info("Starting script: {}", pathToMain);
- Map> ixiMap = new HashMap<>();
- Map startStop = new HashMap<>();
+ try (Reader ixiModuleReader = new FileReader(pathToMain.toFile())) {
+ log.info("Starting script: {}", pathToMain);
+ Map> ixiMap = new HashMap<>();
+ Map startStop = new HashMap<>();
- Bindings bindings = scriptEngine.createBindings();
- bindings.put("API", ixiMap);
- bindings.put("IXICycle", startStop);
- bindings.put("IOTA", iota);
+ Bindings bindings = scriptEngine.createBindings();
+ bindings.put("API", ixiMap);
+ bindings.put("IXICycle", startStop);
+ bindings.put("IOTA", iota);
- ixiAPI.put(moduleName, ixiMap);
- ixiLifetime.put(moduleName, startStop);
- try {
- scriptEngine.eval(ixiModuleReader, bindings);
- } catch (ScriptException e) {
- log.error("Script error", e);
- }
- try {
- ixiModuleReader.close();
+ ixiAPI.put(moduleName, ixiMap);
+ ixiLifetime.put(moduleName, startStop);
+ try {
+ scriptEngine.eval(ixiModuleReader, bindings);
+ } catch (ScriptException e) {
+ log.error("Script error", e);
+ }
} catch (IOException e) {
- log.error("Could not close {}", pathToMain);
+ log.error("Could not load {}", pathToMain);
}
}