Browse Source

close streams passed in to zipFile(InputStream, ...). PR 42632.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@706674 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 16 years ago
parent
commit
8aaa005834
2 changed files with 34 additions and 12 deletions
  1. +32
    -11
      src/main/org/apache/tools/ant/taskdefs/Jar.java
  2. +2
    -1
      src/main/org/apache/tools/ant/taskdefs/Zip.java

+ 32
- 11
src/main/org/apache/tools/ant/taskdefs/Jar.java View File

@@ -431,11 +431,21 @@ public class Jar extends Zip {
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 @@ public class Jar extends Zip {

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 @@ public class Jar extends Zip {
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.


+ 2
- 1
src/main/org/apache/tools/ant/taskdefs/Zip.java View File

@@ -1465,7 +1465,8 @@ public class Zip extends MatchingTask {
/**
* 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.


Loading…
Cancel
Save