diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregator.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregator.java index a8edf1912..fd41e08c3 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregator.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregator.java @@ -211,11 +211,9 @@ public class XMLResultAggregator extends Task implements XMLConstants { * @throws IOException thrown if there is an error while writing the content. */ protected void writeDOMTree(Document doc, File file) throws IOException { - OutputStream out = null; - PrintWriter wri = null; + OutputStream os = new FileOutputStream(file); try { - out = new BufferedOutputStream(new FileOutputStream(file)); - wri = new PrintWriter(new OutputStreamWriter(out, "UTF8")); + PrintWriter wri = new PrintWriter(new OutputStreamWriter(new BufferedOutputStream(os), "UTF8")); wri.write("\n"); (new DOMElementWriter()).write(doc.getDocumentElement(), wri, 0, " "); wri.flush(); @@ -224,8 +222,7 @@ public class XMLResultAggregator extends Task implements XMLConstants { throw new IOException("Error while writing DOM content"); } } finally { - FileUtils.close(wri); - FileUtils.close(out); + os.close(); } }