Skip to content

Commit

Permalink
BZ-19516 Use BufferedInputStream for reduced memory usage in Zip task…
Browse files Browse the repository at this point in the history
…, in certain cases
  • Loading branch information
jaikiran committed Dec 12, 2017
1 parent 485b92f commit 759a9c1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 5 additions & 0 deletions WHATSNEW
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ Fixed bugs:
up creating a new symlink under the target directory.
Bugzilla Report 58683

* Improvement to the Zip task for reduced memory usage in certain
cases. Thanks to Glen Lewis for reporting the issue and
suggesting the fix.
Bugzilla Report 19516

Other changes:
--------------

Expand Down
9 changes: 5 additions & 4 deletions src/main/org/apache/tools/ant/taskdefs/Zip.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package org.apache.tools.ant.taskdefs;

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
Expand Down Expand Up @@ -1077,15 +1078,15 @@ private void addResource(final Resource r, final String name, final String prefi
if (keepCompression) {
doCompress = (ze.getMethod() == ZipEntry.DEFLATED);
}
try (InputStream is = zf.getInputStream(ze)) {
try (final BufferedInputStream is = new BufferedInputStream(zf.getInputStream(ze))) {
zipFile(is, zOut, prefix + name, ze.getTime(),
fromArchive, mode, ze.getExtraFields(true));
} finally {
doCompress = oldCompress;
}
}
} else {
try (InputStream is = r.getInputStream()) {
try (final BufferedInputStream is = new BufferedInputStream(r.getInputStream())) {
zipFile(is, zOut, prefix + name, r.getLastModified(),
fromArchive, mode, r instanceof ZipResource
? ((ZipResource) r).getExtraFields() : null);
Expand Down Expand Up @@ -1916,9 +1917,9 @@ protected void zipFile(final File file, final ZipOutputStream zOut, final String
getLocation());
}

try (InputStream fIn = Files.newInputStream(file.toPath())) {
try (final BufferedInputStream bIn = new BufferedInputStream(Files.newInputStream(file.toPath()))) {
// ZIPs store time with a granularity of 2 seconds, round up
zipFile(fIn, zOut, vPath,
zipFile(bIn, zOut, vPath,
file.lastModified() + (roundUp ? ROUNDUP_MILLIS : 0),
null, mode);
}
Expand Down

0 comments on commit 759a9c1

Please sign in to comment.