Browse Source

Make sure files are getting closed.

Submitted by:	Nico Seessle <nico@seessle.de>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268057 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 24 years ago
parent
commit
3858aba32e
2 changed files with 22 additions and 7 deletions
  1. +9
    -1
      src/main/org/apache/tools/ant/taskdefs/Filter.java
  2. +13
    -6
      src/main/org/apache/tools/ant/taskdefs/SendEmail.java

+ 9
- 1
src/main/org/apache/tools/ant/taskdefs/Filter.java View File

@@ -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) {}
}
}
}
}

+ 13
- 6
src/main/org/apache/tools/ant/taskdefs/SendEmail.java View File

@@ -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 {
}
}

}
}

Loading…
Cancel
Save