Author: jglick
Date: Mon Feb 27 21:35:24 2012
New Revision: 1294340

URL: http://svn.apache.org/viewvc?rev=1294340&view=rev
Log:
#52738: safer stream closing.

Modified:
    
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregator.java

Modified: 
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregator.java
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregator.java?rev=1294340&r1=1294339&r2=1294340&view=diff
==============================================================================
--- 
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregator.java
 (original)
+++ 
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregator.java
 Mon Feb 27 21:35:24 2012
@@ -211,11 +211,9 @@ public class XMLResultAggregator extends
      * @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("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
             (new DOMElementWriter()).write(doc.getDocumentElement(), wri, 0, " 
 ");
             wri.flush();
@@ -224,8 +222,7 @@ public class XMLResultAggregator extends
                 throw new IOException("Error while writing DOM content");
             }
         } finally {
-            FileUtils.close(wri);
-            FileUtils.close(out);
+            os.close();
         }
     }
 


Reply via email to