Cleanups: Close resources via try-finally

We can't use try-with-resources until we bump the minimum-supported Android
version for the client library to API 19.
This commit is contained in:
str4d
2017-12-09 01:02:17 +00:00
parent fe5e4a2c7a
commit a67ea4b2f2
14 changed files with 81 additions and 46 deletions

View File

@@ -1,5 +1,7 @@
package net.i2p.jetty;
import java.io.IOException;
// Contains code from org.mortbay.xml.XmlConfiguation:
// ========================================================================
@@ -17,6 +19,7 @@ package net.i2p.jetty;
// ========================================================================
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -79,14 +82,24 @@ public class JettyStart implements ClientApp {
public void parseArgs(String[] args) throws Exception {
Properties properties=new Properties();
XmlConfiguration last=null;
InputStream in = null;
Resource r = null;
for (int i = 0; i < args.length; i++) {
if (args[i].toLowerCase().endsWith(".properties")) {
in = Resource.newResource(args[i]).getInputStream();
properties.load(in);
in.close();
try {
r = Resource.newResource(args[i]);
properties.load(r.getInputStream());
} finally {
if (r != null) r.close();
}
} else {
XmlConfiguration configuration = new XmlConfiguration(Resource.newResource(args[i]).getURL());
URL configUrl;
try {
r = Resource.newResource(args[i]);
configUrl = r.getURL();
} finally {
if (r != null) r.close();
}
XmlConfiguration configuration = new XmlConfiguration(configUrl);
if (last!=null)
configuration.getIdMap().putAll(last.getIdMap());
if (properties.size()>0) {