Browse Source

#52738: safer stream closing.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1294340 13f79535-47bb-0310-9956-ffa450edef68
master
Jesse N. Glick 13 years ago
parent
commit
5f0f831119
1 changed files with 3 additions and 6 deletions
  1. +3
    -6
      src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregator.java

+ 3
- 6
src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregator.java View File

@@ -211,11 +211,9 @@ public class XMLResultAggregator extends Task implements XMLConstants {
* @throws IOException thrown if there is an error while writing the content. * @throws IOException thrown if there is an error while writing the content.
*/ */
protected void writeDOMTree(Document doc, File file) throws IOException { protected void writeDOMTree(Document doc, File file) throws IOException {
OutputStream out = null;
PrintWriter wri = null;
OutputStream os = new FileOutputStream(file);
try { 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("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"); wri.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
(new DOMElementWriter()).write(doc.getDocumentElement(), wri, 0, " "); (new DOMElementWriter()).write(doc.getDocumentElement(), wri, 0, " ");
wri.flush(); wri.flush();
@@ -224,8 +222,7 @@ public class XMLResultAggregator extends Task implements XMLConstants {
throw new IOException("Error while writing DOM content"); throw new IOException("Error while writing DOM content");
} }
} finally { } finally {
FileUtils.close(wri);
FileUtils.close(out);
os.close();
} }
} }




Loading…
Cancel
Save