Cleanups: Close resources via try-finally

This commit is contained in:
str4d
2018-02-17 19:53:30 +00:00
parent fb6eea2484
commit acebd2ea68
3 changed files with 19 additions and 15 deletions

View File

@@ -261,7 +261,10 @@ public class SingleFileNamingService extends NamingService {
if (out != null) try { out.close(); } catch (IOException e) {}
_log.error("Error adding " + hostname, ioe);
return false;
} finally { releaseWriteLock(); }
} finally {
if (out != null) try { out.close(); } catch (IOException e) {}
releaseWriteLock();
}
}
/**

View File

@@ -394,12 +394,11 @@ public class TranslateReader extends FilterReader {
}
private static void test(String file) throws IOException {
FileInputStream fio = new FileInputStream(file);
TranslateReader r = null;
try {
r = new TranslateReader(I2PAppContext.getGlobalContext(),
"net.i2p.router.web.messages",
fio);
new FileInputStream(file));
int c;
while ((c = r.read()) >= 0) {
System.out.print((char)c);

View File

@@ -64,19 +64,21 @@ public class MultiRouter {
usage();
return;
}
Scanner scan = new Scanner(args[0]);
if (!scan.hasNextInt()) {
usage();
scan.close();
return;
Scanner scan = null;
try {
scan = new Scanner(args[0]);
if (!scan.hasNextInt()) {
usage();
return;
}
nbrRouters = scan.nextInt();
if (nbrRouters < 0) {
usage();
return;
}
} finally {
if (scan != null) scan.close();
}
nbrRouters = scan.nextInt();
if (nbrRouters < 0) {
usage();
scan.close();
return;
}
scan.close();
_out = System.out;