Verified Commit d06c41cc authored by Amin Bandali's avatar Amin Bandali
Browse files

Flush Writers and PrintWriters before closing them

parent 9731343c
......@@ -124,7 +124,7 @@ public abstract class CatalystCommand {
return w;
}
protected void writeWriter(Writer w, String s, Path f) {
protected void writerWrite(Writer w, String s, Path f) {
try {
w.write(s);
}
......@@ -134,7 +134,17 @@ public abstract class CatalystCommand {
}
}
protected void closeWriter(Writer w, Path f) {
protected void writerFlush(Writer w, Path f) {
try {
w.flush();
}
catch (IOException e) {
pf("I/O error occured while trying to flush %s writer:%n", f.toString());
pln(Utils.toString(e));
}
}
protected void writerClose(Writer w, Path f) {
try {
wjson.close();
}
......@@ -144,6 +154,12 @@ public abstract class CatalystCommand {
}
}
protected void writerWriteFlushClose(Writer w, String s, Path f) {
writerWrite(w, s, f);
writerFlush(w, f);
writerClose(w, f);
}
protected void p(String s) {
System.out.print(s);
ptxt.print(s);
......
......@@ -112,11 +112,10 @@ public final class Mut extends CatalystCommand implements Runnable {
pln(String.format("total error count: %d", r.total_error_count));
pln(String.format("total elapsed time: %dms", r.total_elapsed_time));
writeWriter(wjson, gson.toJson(r), oj);
closeWriter(wjson, oj);
writeWriter(ejson, gson.toJson(errors), ej);
closeWriter(ejson, ej);
writerWriteFlushClose(wjson, gson.toJson(r), oj);
writerWriteFlushClose(ejson, gson.toJson(errors), ej);
ptxt.flush();
ptxt.close();
}
......@@ -231,8 +230,7 @@ public final class Mut extends CatalystCommand implements Runnable {
pln(progress + "done: " + fr.file_name);
writeWriter(w, gson.toJson(fr), outFile);
closeWriter(w, outFile);
writerWriteFlushClose(w, gson.toJson(fr), outFile);
return fr;
}
......
......@@ -70,11 +70,10 @@ public final class SSR extends CatalystCommand implements Runnable {
pln(String.format("total error count: %d", r.total_error_count));
pln(String.format("total elapsed time: %dms", r.total_elapsed_time));
writeWriter(wjson, gson.toJson(r), oj);
closeWriter(wjson, oj);
writeWriter(ejson, gson.toJson(errors), ej);
closeWriter(ejson, ej);
writerWriteFlushClose(wjson, gson.toJson(r), oj);
writerWriteFlushClose(ejson, gson.toJson(errors), ej);
ptxt.flush();
ptxt.close();
}
......@@ -190,8 +189,7 @@ public final class SSR extends CatalystCommand implements Runnable {
pln(progress + finalStatus + ": " + fr.file_name);
writeWriter(w, gson.toJson(fr), outFile);
closeWriter(w, outFile);
writerWriteFlushClose(w, gson.toJson(fr), outFile);
return fr;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment