diff --git a/src/main/org/apache/tools/ant/taskdefs/Filter.java b/src/main/org/apache/tools/ant/taskdefs/Filter.java index aac5b4fa7..c2e6c02de 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Filter.java +++ b/src/main/org/apache/tools/ant/taskdefs/Filter.java @@ -106,9 +106,11 @@ public class Filter extends Task { protected void readFilters() throws BuildException { log("Reading filters from " + filtersFile, Project.MSG_VERBOSE); + FileInputStream in = null; try { Properties props = new Properties(); - props.load(new FileInputStream(filtersFile)); + in = new FileInputStream(filtersFile); + props.load(in); Project proj = getProject(); @@ -120,6 +122,12 @@ public class Filter extends Task { } } catch (Exception e) { throw new BuildException("Could not read filters from file: " + filtersFile); + } finally { + if (in != null) { + try { + in.close(); + } catch (java.io.IOException ioex) {} + } } } } diff --git a/src/main/org/apache/tools/ant/taskdefs/SendEmail.java b/src/main/org/apache/tools/ant/taskdefs/SendEmail.java index 3e60987d9..6a6458419 100644 --- a/src/main/org/apache/tools/ant/taskdefs/SendEmail.java +++ b/src/main/org/apache/tools/ant/taskdefs/SendEmail.java @@ -216,11 +216,18 @@ public class SendEmail extends Task { int length; byte[] buf = new byte[bufsize]; - BufferedInputStream in = new BufferedInputStream( - new FileInputStream(file), bufsize); - - while ((length = in.read(buf, 0, bufsize)) != -1) { - out.write(buf, 0, length); + BufferedInputStream in = null; + try { + in = new BufferedInputStream( + new FileInputStream(file), bufsize); + + while ((length = in.read(buf, 0, bufsize)) != -1) { + out.write(buf, 0, length); + } + } finally { + if (in != null) { + in.close(); + } } } else { @@ -242,4 +249,4 @@ public class SendEmail extends Task { } } -} \ No newline at end of file +}