ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r905214 - in /ant/core/trunk/src/main/org/apache/tools/ant/taskdefs: KeySubst.java optional/i18n/Translate.java optional/junit/JUnitTestRunner.java optional/junit/XMLJUnitResultFormatter.java optional/net/FTP.java optional/pvcs/Pvcs.java
Date Mon, 01 Feb 2010 08:56:38 GMT
Author: bodewig
Date: Mon Feb  1 08:56:37 2010
New Revision: 905214

URL: http://svn.apache.org/viewvc?rev=905214&view=rev
Log:
More FileUtils.close and a moved flush operation in XMLJUnitresultFormatter

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/KeySubst.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/pvcs/Pvcs.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/KeySubst.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/KeySubst.java?rev=905214&r1=905213&r2=905214&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/KeySubst.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/KeySubst.java Mon Feb  1 08:56:37
2010
@@ -28,6 +28,7 @@
 import java.util.StringTokenizer;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Task;
+import org.apache.tools.ant.util.FileUtils;
 
 /**
  * Keyword substitution. Input file is written to output file.
@@ -80,20 +81,8 @@
         } catch (IOException ioe) {
             ioe.printStackTrace();
         } finally {
-            if (bw != null) {
-                try {
-                    bw.close();
-                } catch (IOException e) {
-                    // ignore
-                }
-            }
-            if (br != null) {
-                try {
-                    br.close();
-                } catch (IOException e) {
-                    // ignore
-                }
-            }
+            FileUtils.close(bw);
+            FileUtils.close(br);
         }
     }
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java?rev=905214&r1=905213&r2=905214&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java Mon
Feb  1 08:56:37 2010
@@ -530,11 +530,14 @@
                     if (needsWork) {
                         log("Processing " + srcFiles[j],
                             Project.MSG_DEBUG);
+                        BufferedWriter out = null;
+                        BufferedReader in = null;
+                        try {
                         FileOutputStream fos = new FileOutputStream(dest);
-                        BufferedWriter out
+                            out
                             = new BufferedWriter(new OutputStreamWriter(fos, destEncoding));
                         FileInputStream fis = new FileInputStream(src);
-                        BufferedReader in
+                            in
                             = new BufferedReader(new InputStreamReader(fis, srcEncoding));
                         String line;
                         LineTokenizer lineTokenizer = new LineTokenizer();
@@ -605,11 +608,9 @@
                             out.write(line);
                             line = lineTokenizer.getToken(in);
                         }
-                        if (in != null) {
-                            in.close();
-                        }
-                        if (out != null) {
-                            out.close();
+                        } finally {
+                            FileUtils.close(in);
+                            FileUtils.close(out);
                         }
                         ++filesProcessed;
                     } else {

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java?rev=905214&r1=905213&r2=905214&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
Mon Feb  1 08:56:37 2010
@@ -944,9 +944,7 @@
                 out.write(Constants.TERMINATED_SUCCESSFULLY + "\n");
                 out.flush();
             } finally {
-                if (out != null) {
-                    out.close();
-                }
+                FileUtils.close(out);
             }
         }
     }
@@ -960,9 +958,7 @@
                     out.write(testCase + "\n");
                     out.flush();
                 } finally {
-                    if (out != null) {
-                        out.close();
-                    }
+                    FileUtils.close(out);
                 }
             } catch (IOException e) {
                 // ignored.

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java?rev=905214&r1=905213&r2=905214&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java
Mon Feb  1 08:56:37 2010
@@ -169,10 +169,16 @@
                 wri = new BufferedWriter(new OutputStreamWriter(out, "UTF8"));
                 wri.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
                 (new DOMElementWriter()).write(rootElement, wri, 0, "  ");
-                wri.flush();
             } catch (IOException exc) {
                 throw new BuildException("Unable to write log file", exc);
             } finally {
+                if (wri != null) {
+                    try {
+                        wri.flush();
+                    } catch (IOException ex) {
+                        // ignore
+                    }
+                }
                 if (out != System.out && out != System.err) {
                     FileUtils.close(wri);
                 }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java?rev=905214&r1=905213&r2=905214&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java Mon Feb  1
08:56:37 2010
@@ -1799,9 +1799,7 @@
                 }
             }
         } finally {
-            if (bw != null) {
-                bw.close();
-            }
+            FileUtils.close(bw);
         }
 
         return dsfiles.length;
@@ -2158,13 +2156,7 @@
                 transferred++;
             }
         } finally {
-            if (instream != null) {
-                try {
-                    instream.close();
-                } catch (IOException ex) {
-                    // ignore it
-                }
-            }
+            FileUtils.close(instream);
         }
     }
 
@@ -2295,13 +2287,7 @@
                 }
             }
         } finally {
-            if (outstream != null) {
-                try {
-                    outstream.close();
-                } catch (IOException ex) {
-                    // ignore it
-                }
-            }
+            FileUtils.close(outstream);
         }
     }
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/pvcs/Pvcs.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/pvcs/Pvcs.java?rev=905214&r1=905213&r2=905214&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/pvcs/Pvcs.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/pvcs/Pvcs.java Mon Feb
 1 08:56:37 2010
@@ -38,6 +38,7 @@
 import org.apache.tools.ant.taskdefs.LogStreamHandler;
 import org.apache.tools.ant.taskdefs.PumpStreamHandler;
 import org.apache.tools.ant.types.Commandline;
+import org.apache.tools.ant.util.FileUtils;
 
 /**
  *
@@ -205,7 +206,7 @@
                                     new LogOutputStream(this,
                                                         Project.MSG_WARN)));
             } finally {
-                fos.close();
+                FileUtils.close(fos);
             }
 
             if (Execute.isFailure(result) && !ignorerc) {
@@ -340,9 +341,7 @@
                 line = in.readLine();
             }
         } finally {
-            if (in != null) {
-                in.close();
-            }
+            FileUtils.close(in);
         }
     }
 
@@ -366,12 +365,8 @@
                 outWriter.newLine();
             }
         } finally {
-            if (inReader != null) {
-                inReader.close();
-            }
-            if (outWriter != null) {
-                outWriter.close();
-            }
+            FileUtils.close(inReader);
+            FileUtils.close(outWriter);
         }
     }
 



Mime
View raw message