提交 24162d15 authored 作者: noelgrandin's avatar noelgrandin

simplify code and make Eclipse's resource-close checker happy

上级 2508d2a2
...@@ -7,11 +7,11 @@ ...@@ -7,11 +7,11 @@
package org.h2.test.coverage; package org.h2.test.coverage;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.Closeable;
import java.io.FileReader; import java.io.FileReader;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.LineNumberReader; import java.io.LineNumberReader;
import java.io.Reader;
import java.io.Writer; import java.io.Writer;
/** /**
...@@ -31,10 +31,9 @@ public class Profile extends Thread { ...@@ -31,10 +31,9 @@ public class Profile extends Thread {
private BufferedWriter trace; private BufferedWriter trace;
private Profile() { private Profile() {
FileReader reader = null; LineNumberReader r = null;
try { try {
reader = new FileReader("profile.txt"); r = new LineNumberReader(new FileReader("profile.txt"));
LineNumberReader r = new LineNumberReader(reader);
while (r.readLine() != null) { while (r.readLine() != null) {
// nothing - just count lines // nothing - just count lines
} }
...@@ -47,7 +46,7 @@ public class Profile extends Thread { ...@@ -47,7 +46,7 @@ public class Profile extends Thread {
e.printStackTrace(); e.printStackTrace();
System.exit(1); System.exit(1);
} finally { } finally {
closeSilently(reader); closeSilently(r);
} }
} }
...@@ -108,20 +107,10 @@ public class Profile extends Thread { ...@@ -108,20 +107,10 @@ public class Profile extends Thread {
} }
} }
private static void closeSilently(Reader reader) { private static void closeSilently(Closeable closeable) {
if (reader != null) { if (closeable != null) {
try {
reader.close();
} catch (IOException e) {
// ignore
}
}
}
private static void closeSilently(Writer writer) {
if (writer != null) {
try { try {
writer.close(); closeable.close();
} catch (IOException e) { } catch (IOException e) {
// ignore // ignore
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论