Author: bodewig
Date: Tue Oct 21 09:04:52 2008
New Revision: 706674
URL: http://svn.apache.org/viewvc?rev=706674&view=rev
Log:
close streams passed in to zipFile(InputStream, ...). PR 42632.
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Jar.java
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Zip.java
Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Jar.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Jar.java?rev=706674&r1=706673&r2=706674&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Jar.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Jar.java Tue Oct 21
09:04:52 2008
@@ -431,11 +431,21 @@
serviceIterator = serviceList.iterator();
while (serviceIterator.hasNext()) {
service = (Service) serviceIterator.next();
- //stolen from writeManifest
- super.zipFile(service.getAsStream(), zOut,
- "META-INF/services/" + service.getType(),
- System.currentTimeMillis(), null,
- ZipFileSet.DEFAULT_FILE_MODE);
+
+ InputStream is = null;
+ try {
+ is = service.getAsStream();
+ //stolen from writeManifest
+ super.zipFile(is, zOut,
+ "META-INF/services/" + service.getType(),
+ System.currentTimeMillis(), null,
+ ZipFileSet.DEFAULT_FILE_MODE);
+ } finally {
+ // technically this is unnecessary since
+ // Service.getAsStream returns a ByteArrayInputStream
+ // and not closing it wouldn't do any harm.
+ FileUtils.close(is);
+ }
}
}
@@ -511,9 +521,14 @@
ByteArrayInputStream bais =
new ByteArrayInputStream(baos.toByteArray());
- super.zipFile(bais, zOut, MANIFEST_NAME,
- System.currentTimeMillis(), null,
- ZipFileSet.DEFAULT_FILE_MODE);
+ try {
+ super.zipFile(bais, zOut, MANIFEST_NAME,
+ System.currentTimeMillis(), null,
+ ZipFileSet.DEFAULT_FILE_MODE);
+ } finally {
+ // not really required
+ FileUtils.close(bais);
+ }
super.initZipOutputStream(zOut);
}
@@ -592,13 +607,19 @@
writer.close();
ByteArrayInputStream bais =
new ByteArrayInputStream(baos.toByteArray());
- super.zipFile(bais, zOut, INDEX_NAME, System.currentTimeMillis(), null,
- ZipFileSet.DEFAULT_FILE_MODE);
+ try {
+ super.zipFile(bais, zOut, INDEX_NAME, System.currentTimeMillis(),
+ null, ZipFileSet.DEFAULT_FILE_MODE);
+ } finally {
+ // not really required
+ FileUtils.close(bais);
+ }
}
/**
* Overridden from Zip class to deal with manifests and index lists.
- * @param is the input stream
+ * @param in the stream to read data for the entry from. The
+ * caller of the method is responsible for closing the stream.
* @param zOut the zip output stream
* @param vPath the name this entry shall have in the archive
* @param lastModified last modification time for the entry.
Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Zip.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Zip.java?rev=706674&r1=706673&r2=706674&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Zip.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Zip.java Tue Oct 21
09:04:52 2008
@@ -1465,7 +1465,8 @@
/**
* Adds a new entry to the archive, takes care of duplicates as well.
*
- * @param in the stream to read data for the entry from.
+ * @param in the stream to read data for the entry from. The
+ * caller of the method is responsible for closing the stream.
* @param zOut the stream to write to.
* @param vPath the name this entry shall have in the archive.
* @param lastModified last modification time for the entry.