git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@905214 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -28,6 +28,7 @@ import java.util.Hashtable; | |||||
| import java.util.StringTokenizer; | import java.util.StringTokenizer; | ||||
| import org.apache.tools.ant.BuildException; | import org.apache.tools.ant.BuildException; | ||||
| import org.apache.tools.ant.Task; | import org.apache.tools.ant.Task; | ||||
| import org.apache.tools.ant.util.FileUtils; | |||||
| /** | /** | ||||
| * Keyword substitution. Input file is written to output file. | * Keyword substitution. Input file is written to output file. | ||||
| @@ -80,20 +81,8 @@ public class KeySubst extends Task { | |||||
| } catch (IOException ioe) { | } catch (IOException ioe) { | ||||
| ioe.printStackTrace(); | ioe.printStackTrace(); | ||||
| } finally { | } 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); | |||||
| } | } | ||||
| } | } | ||||
| @@ -530,11 +530,14 @@ public class Translate extends MatchingTask { | |||||
| if (needsWork) { | if (needsWork) { | ||||
| log("Processing " + srcFiles[j], | log("Processing " + srcFiles[j], | ||||
| Project.MSG_DEBUG); | Project.MSG_DEBUG); | ||||
| BufferedWriter out = null; | |||||
| BufferedReader in = null; | |||||
| try { | |||||
| FileOutputStream fos = new FileOutputStream(dest); | FileOutputStream fos = new FileOutputStream(dest); | ||||
| BufferedWriter out | |||||
| out | |||||
| = new BufferedWriter(new OutputStreamWriter(fos, destEncoding)); | = new BufferedWriter(new OutputStreamWriter(fos, destEncoding)); | ||||
| FileInputStream fis = new FileInputStream(src); | FileInputStream fis = new FileInputStream(src); | ||||
| BufferedReader in | |||||
| in | |||||
| = new BufferedReader(new InputStreamReader(fis, srcEncoding)); | = new BufferedReader(new InputStreamReader(fis, srcEncoding)); | ||||
| String line; | String line; | ||||
| LineTokenizer lineTokenizer = new LineTokenizer(); | LineTokenizer lineTokenizer = new LineTokenizer(); | ||||
| @@ -605,11 +608,9 @@ public class Translate extends MatchingTask { | |||||
| out.write(line); | out.write(line); | ||||
| line = lineTokenizer.getToken(in); | line = lineTokenizer.getToken(in); | ||||
| } | } | ||||
| if (in != null) { | |||||
| in.close(); | |||||
| } | |||||
| if (out != null) { | |||||
| out.close(); | |||||
| } finally { | |||||
| FileUtils.close(in); | |||||
| FileUtils.close(out); | |||||
| } | } | ||||
| ++filesProcessed; | ++filesProcessed; | ||||
| } else { | } else { | ||||
| @@ -944,9 +944,7 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR | |||||
| out.write(Constants.TERMINATED_SUCCESSFULLY + "\n"); | out.write(Constants.TERMINATED_SUCCESSFULLY + "\n"); | ||||
| out.flush(); | out.flush(); | ||||
| } finally { | } finally { | ||||
| if (out != null) { | |||||
| out.close(); | |||||
| } | |||||
| FileUtils.close(out); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -960,9 +958,7 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR | |||||
| out.write(testCase + "\n"); | out.write(testCase + "\n"); | ||||
| out.flush(); | out.flush(); | ||||
| } finally { | } finally { | ||||
| if (out != null) { | |||||
| out.close(); | |||||
| } | |||||
| FileUtils.close(out); | |||||
| } | } | ||||
| } catch (IOException e) { | } catch (IOException e) { | ||||
| // ignored. | // ignored. | ||||
| @@ -169,10 +169,16 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan | |||||
| wri = new BufferedWriter(new OutputStreamWriter(out, "UTF8")); | wri = new BufferedWriter(new OutputStreamWriter(out, "UTF8")); | ||||
| wri.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"); | wri.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"); | ||||
| (new DOMElementWriter()).write(rootElement, wri, 0, " "); | (new DOMElementWriter()).write(rootElement, wri, 0, " "); | ||||
| wri.flush(); | |||||
| } catch (IOException exc) { | } catch (IOException exc) { | ||||
| throw new BuildException("Unable to write log file", exc); | throw new BuildException("Unable to write log file", exc); | ||||
| } finally { | } finally { | ||||
| if (wri != null) { | |||||
| try { | |||||
| wri.flush(); | |||||
| } catch (IOException ex) { | |||||
| // ignore | |||||
| } | |||||
| } | |||||
| if (out != System.out && out != System.err) { | if (out != System.out && out != System.err) { | ||||
| FileUtils.close(wri); | FileUtils.close(wri); | ||||
| } | } | ||||
| @@ -1799,9 +1799,7 @@ public class FTP extends Task implements FTPTaskConfig { | |||||
| } | } | ||||
| } | } | ||||
| } finally { | } finally { | ||||
| if (bw != null) { | |||||
| bw.close(); | |||||
| } | |||||
| FileUtils.close(bw); | |||||
| } | } | ||||
| return dsfiles.length; | return dsfiles.length; | ||||
| @@ -2158,13 +2156,7 @@ public class FTP extends Task implements FTPTaskConfig { | |||||
| transferred++; | transferred++; | ||||
| } | } | ||||
| } finally { | } finally { | ||||
| if (instream != null) { | |||||
| try { | |||||
| instream.close(); | |||||
| } catch (IOException ex) { | |||||
| // ignore it | |||||
| } | |||||
| } | |||||
| FileUtils.close(instream); | |||||
| } | } | ||||
| } | } | ||||
| @@ -2295,13 +2287,7 @@ public class FTP extends Task implements FTPTaskConfig { | |||||
| } | } | ||||
| } | } | ||||
| } finally { | } finally { | ||||
| if (outstream != null) { | |||||
| try { | |||||
| outstream.close(); | |||||
| } catch (IOException ex) { | |||||
| // ignore it | |||||
| } | |||||
| } | |||||
| FileUtils.close(outstream); | |||||
| } | } | ||||
| } | } | ||||
| @@ -38,6 +38,7 @@ import org.apache.tools.ant.taskdefs.LogOutputStream; | |||||
| import org.apache.tools.ant.taskdefs.LogStreamHandler; | import org.apache.tools.ant.taskdefs.LogStreamHandler; | ||||
| import org.apache.tools.ant.taskdefs.PumpStreamHandler; | import org.apache.tools.ant.taskdefs.PumpStreamHandler; | ||||
| import org.apache.tools.ant.types.Commandline; | import org.apache.tools.ant.types.Commandline; | ||||
| import org.apache.tools.ant.util.FileUtils; | |||||
| /** | /** | ||||
| * | * | ||||
| @@ -205,7 +206,7 @@ public class Pvcs extends org.apache.tools.ant.Task { | |||||
| new LogOutputStream(this, | new LogOutputStream(this, | ||||
| Project.MSG_WARN))); | Project.MSG_WARN))); | ||||
| } finally { | } finally { | ||||
| fos.close(); | |||||
| FileUtils.close(fos); | |||||
| } | } | ||||
| if (Execute.isFailure(result) && !ignorerc) { | if (Execute.isFailure(result) && !ignorerc) { | ||||
| @@ -340,9 +341,7 @@ public class Pvcs extends org.apache.tools.ant.Task { | |||||
| line = in.readLine(); | line = in.readLine(); | ||||
| } | } | ||||
| } finally { | } finally { | ||||
| if (in != null) { | |||||
| in.close(); | |||||
| } | |||||
| FileUtils.close(in); | |||||
| } | } | ||||
| } | } | ||||
| @@ -366,12 +365,8 @@ public class Pvcs extends org.apache.tools.ant.Task { | |||||
| outWriter.newLine(); | outWriter.newLine(); | ||||
| } | } | ||||
| } finally { | } finally { | ||||
| if (inReader != null) { | |||||
| inReader.close(); | |||||
| } | |||||
| if (outWriter != null) { | |||||
| outWriter.close(); | |||||
| } | |||||
| FileUtils.close(inReader); | |||||
| FileUtils.close(outWriter); | |||||
| } | } | ||||
| } | } | ||||