git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@905179 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -1203,9 +1203,7 @@ public class Execute { | |||||
| out.write(cmd[i]); | out.write(cmd[i]); | ||||
| } | } | ||||
| } finally { | } finally { | ||||
| if (out != null) { | |||||
| out.close(); | |||||
| } | |||||
| FileUtils.close(out); | |||||
| } | } | ||||
| return script; | return script; | ||||
| } | } | ||||
| @@ -26,6 +26,7 @@ import java.io.OutputStreamWriter; | |||||
| import java.io.PrintStream; | import java.io.PrintStream; | ||||
| import org.apache.tools.ant.ProjectComponent; | import org.apache.tools.ant.ProjectComponent; | ||||
| import org.apache.tools.ant.util.FileUtils; | |||||
| /** | /** | ||||
| * Class representing an email message. | * Class representing an email message. | ||||
| @@ -115,7 +116,9 @@ public class Message extends ProjectComponent { | |||||
| throws IOException { | throws IOException { | ||||
| // We need character encoding aware printing here. | // We need character encoding aware printing here. | ||||
| // So, using BufferedWriter over OutputStreamWriter instead of PrintStream | // So, using BufferedWriter over OutputStreamWriter instead of PrintStream | ||||
| BufferedWriter out | |||||
| BufferedWriter out = null; | |||||
| try { | |||||
| out | |||||
| = charset != null ? new BufferedWriter(new OutputStreamWriter(ps, charset)) | = charset != null ? new BufferedWriter(new OutputStreamWriter(ps, charset)) | ||||
| : new BufferedWriter(new OutputStreamWriter(ps)); | : new BufferedWriter(new OutputStreamWriter(ps)); | ||||
| if (messageSource != null) { | if (messageSource != null) { | ||||
| @@ -137,6 +140,9 @@ public class Message extends ProjectComponent { | |||||
| out.newLine(); | out.newLine(); | ||||
| } | } | ||||
| out.flush(); | out.flush(); | ||||
| } finally { | |||||
| FileUtils.close(out); | |||||
| } | |||||
| } | } | ||||
| @@ -179,14 +179,18 @@ public class Cab extends MatchingTask { | |||||
| throws IOException { | throws IOException { | ||||
| File listFile = FILE_UTILS.createTempFile("ant", "", null, true, true); | File listFile = FILE_UTILS.createTempFile("ant", "", null, true, true); | ||||
| BufferedWriter writer = new BufferedWriter(new FileWriter(listFile)); | |||||
| BufferedWriter writer = null; | |||||
| try { | |||||
| writer = new BufferedWriter(new FileWriter(listFile)); | |||||
| int size = files.size(); | int size = files.size(); | ||||
| for (int i = 0; i < size; i++) { | for (int i = 0; i < size; i++) { | ||||
| writer.write('\"' + files.elementAt(i).toString() + '\"'); | writer.write('\"' + files.elementAt(i).toString() + '\"'); | ||||
| writer.newLine(); | writer.newLine(); | ||||
| } | } | ||||
| writer.close(); | |||||
| } finally { | |||||
| FileUtils.close(writer); | |||||
| } | |||||
| return listFile; | return listFile; | ||||
| } | } | ||||
| @@ -354,6 +354,7 @@ public class ReplaceRegExp extends Task { | |||||
| Reader r = null; | Reader r = null; | ||||
| Writer w = null; | Writer w = null; | ||||
| BufferedWriter bw = null; | |||||
| try { | try { | ||||
| if (encoding == null) { | if (encoding == null) { | ||||
| @@ -366,7 +367,7 @@ public class ReplaceRegExp extends Task { | |||||
| } | } | ||||
| BufferedReader br = new BufferedReader(r); | BufferedReader br = new BufferedReader(r); | ||||
| BufferedWriter bw = new BufferedWriter(w); | |||||
| bw = new BufferedWriter(w); | |||||
| boolean changes = false; | boolean changes = false; | ||||
| @@ -484,6 +485,7 @@ public class ReplaceRegExp extends Task { | |||||
| } | } | ||||
| } finally { | } finally { | ||||
| FileUtils.close(r); | FileUtils.close(r); | ||||
| FileUtils.close(bw); | |||||
| FileUtils.close(w); | FileUtils.close(w); | ||||
| if (temp != null) { | if (temp != null) { | ||||
| temp.delete(); | temp.delete(); | ||||
| @@ -169,10 +169,14 @@ public class BriefJUnitResultFormatter implements JUnitResultFormatter { | |||||
| output.write(sb.toString()); | output.write(sb.toString()); | ||||
| resultWriter.close(); | resultWriter.close(); | ||||
| output.write(results.toString()); | output.write(results.toString()); | ||||
| output.flush(); | |||||
| } catch (IOException ex) { | } catch (IOException ex) { | ||||
| throw new BuildException(ex); | throw new BuildException(ex); | ||||
| } finally { | } finally { | ||||
| try { | |||||
| output.flush(); | |||||
| } catch (IOException ex) { | |||||
| // swallow, there has likely been an exception before this | |||||
| } | |||||
| if (out != System.out && out != System.err) { | if (out != System.out && out != System.err) { | ||||
| FileUtils.close(out); | FileUtils.close(out); | ||||
| } | } | ||||
| @@ -255,9 +255,10 @@ public class FailureRecorder extends ProjectComponent implements JUnitResultForm | |||||
| createSuiteMethod(); | createSuiteMethod(); | ||||
| createClassFooter(); | createClassFooter(); | ||||
| FileUtils.close(writer); | |||||
| } catch (IOException e) { | } catch (IOException e) { | ||||
| e.printStackTrace(); | e.printStackTrace(); | ||||
| } finally { | |||||
| FileUtils.close(writer); | |||||
| } | } | ||||
| } | } | ||||