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

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

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