Skip to content
Snippets Groups Projects
Commit 83da113b authored by Yanjun Jiang's avatar Yanjun Jiang
Browse files

Make EventBFileWriter safe from exceptions.

Make sure all closeable objects in EventBFileWriter are properly closed,
even in the presence of exceptions.
parent 51d4fec4
No related branches found
No related tags found
No related merge requests found
......@@ -28,10 +28,7 @@
*/
package ca.mcscert.jtet.eventbgenerator;
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.*;
/**
*
......@@ -39,14 +36,36 @@ import java.io.OutputStreamWriter;
*/
final public class EventBFileWriter {
public static void writeEventBFile(String fileName, String fileContent) {
public static void writeEventBBumFile(String fileName, String content) throws IOException {
FileOutputStream fos = null;
try {
BufferedWriter br = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName + ".bum"), "UTF8"));
br.write(fileContent);
br.flush();
br.close();
} catch (IOException e) {
e.printStackTrace();
fos = new FileOutputStream(fileName);
OutputStreamWriter osw = null;
try {
osw = new OutputStreamWriter(fos, "UTF8");
BufferedWriter bw = null;
try {
bw = new BufferedWriter(osw);
bw.write(content);
bw.flush();
} finally {
if (bw != null) {
bw.close();
}
}
} finally {
if (osw != null) {
osw.close();
}
}
} finally {
if (fos != null) {
fos.close();
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment