提交 65532d86 authored 作者: Thomas Mueller's avatar Thomas Mueller

Close files; automatic output file name.

上级 b7046902
...@@ -75,11 +75,14 @@ public class ThreadDumpCleaner { ...@@ -75,11 +75,14 @@ public class ThreadDumpCleaner {
outFile = args[++i]; outFile = args[++i];
} }
} }
if (outFile == null) {
outFile = inFile + ".clean.txt";
}
PrintWriter writer; PrintWriter writer;
if (outFile != null) { if ("-".equals(outFile)) {
writer = new PrintWriter(new BufferedWriter(new FileWriter(outFile)));
} else {
writer = new PrintWriter(System.out); writer = new PrintWriter(System.out);
} else {
writer = new PrintWriter(new BufferedWriter(new FileWriter(outFile)));
} }
Reader r; Reader r;
if (inFile != null) { if (inFile != null) {
...@@ -90,6 +93,8 @@ public class ThreadDumpCleaner { ...@@ -90,6 +93,8 @@ public class ThreadDumpCleaner {
new ThreadDumpCleaner().run( new ThreadDumpCleaner().run(
new LineNumberReader(new BufferedReader(r)), new LineNumberReader(new BufferedReader(r)),
writer); writer);
writer.close();
r.close();
} }
private void run(LineNumberReader reader, PrintWriter writer) throws IOException { private void run(LineNumberReader reader, PrintWriter writer) throws IOException {
...@@ -100,7 +105,7 @@ public class ThreadDumpCleaner { ...@@ -100,7 +105,7 @@ public class ThreadDumpCleaner {
break; break;
} }
buff.append(line).append('\n'); buff.append(line).append('\n');
if (line.length() == 0) { if (line.trim().length() == 0) {
writer.print(filter(buff.toString())); writer.print(filter(buff.toString()));
buff = new StringBuilder(); buff = new StringBuilder();
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论