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 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 @@ public class KeySubst extends Task { | |||
} 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); | |||
} | |||
} | |||
@@ -530,11 +530,14 @@ public class Translate extends MatchingTask { | |||
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 @@ public class Translate extends MatchingTask { | |||
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 { | |||
@@ -944,9 +944,7 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR | |||
out.write(Constants.TERMINATED_SUCCESSFULLY + "\n"); | |||
out.flush(); | |||
} 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.flush(); | |||
} finally { | |||
if (out != null) { | |||
out.close(); | |||
} | |||
FileUtils.close(out); | |||
} | |||
} catch (IOException e) { | |||
// ignored. | |||
@@ -169,10 +169,16 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan | |||
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); | |||
} | |||
@@ -1799,9 +1799,7 @@ public class FTP extends Task implements FTPTaskConfig { | |||
} | |||
} | |||
} finally { | |||
if (bw != null) { | |||
bw.close(); | |||
} | |||
FileUtils.close(bw); | |||
} | |||
return dsfiles.length; | |||
@@ -2158,13 +2156,7 @@ public class FTP extends Task implements FTPTaskConfig { | |||
transferred++; | |||
} | |||
} 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 { | |||
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.PumpStreamHandler; | |||
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, | |||
Project.MSG_WARN))); | |||
} finally { | |||
fos.close(); | |||
FileUtils.close(fos); | |||
} | |||
if (Execute.isFailure(result) && !ignorerc) { | |||
@@ -340,9 +341,7 @@ public class Pvcs extends org.apache.tools.ant.Task { | |||
line = in.readLine(); | |||
} | |||
} finally { | |||
if (in != null) { | |||
in.close(); | |||
} | |||
FileUtils.close(in); | |||
} | |||
} | |||
@@ -366,12 +365,8 @@ public class Pvcs extends org.apache.tools.ant.Task { | |||
outWriter.newLine(); | |||
} | |||
} finally { | |||
if (inReader != null) { | |||
inReader.close(); | |||
} | |||
if (outWriter != null) { | |||
outWriter.close(); | |||
} | |||
FileUtils.close(inReader); | |||
FileUtils.close(outWriter); | |||
} | |||
} | |||