Browse Source

Only calculate the CRC of STORED entries in <zip> if absolutely necessary.

PR: 21899


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@275010 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 22 years ago
parent
commit
d13027731c
7 changed files with 80 additions and 11 deletions
  1. +3
    -0
      WHATSNEW
  2. +37
    -0
      docs/external.html
  3. +6
    -0
      src/etc/testcases/taskdefs/unzip.xml
  4. +6
    -0
      src/etc/testcases/taskdefs/zip.xml
  5. +2
    -6
      src/main/org/apache/tools/ant/taskdefs/Zip.java
  6. +19
    -5
      src/main/org/apache/tools/zip/ZipOutputStream.java
  7. +7
    -0
      src/testcases/org/apache/tools/ant/taskdefs/UnzipTest.java

+ 3
- 0
WHATSNEW View File

@@ -548,6 +548,9 @@ If set to true, the process will be spawned. Bugzilla Report 5907.
<parallel> to throw an exception if any thread fails without
waiting for all other threads to complete.

* <zip> and friends will consume far less memory than they used to
when run with compress="false". Bugzilla Report 21899.

Changes from Ant 1.5.2 to Ant 1.5.3
===================================



+ 37
- 0
docs/external.html View File

@@ -3891,6 +3891,43 @@
valign="top" align="left">
Commercial
</td>
</tr>
</table>
<h4 class="subsection">
<a name="Zelix KlassMaster Java Obfuscator"></a>
Zelix KlassMaster Java Obfuscator
</h4>
<p>The task ZKMTask allows the Zelix KlassMaster Java obfuscator to be integrated into an Ant build.</p>
<table class="externals" cellspacing="1" cellpadding="4">
<tr>
<th colspan="1" rowspan="1"
valign="top" align="left">
Compatibility:
</th>
<td colspan="1" rowspan="1"
valign="top" align="left">
Ant 1.4.1
</td>
</tr>
<tr>
<th colspan="1" rowspan="1"
valign="top" align="left">
URL:
</th>
<td colspan="1" rowspan="1"
valign="top" align="left">
<a href="http://www.zelix.com/klassmaster/docs/buildToolApi.html">Zelix KlassMaster Ant Task</a>
</td>
</tr>
<tr>
<th colspan="1" rowspan="1"
valign="top" align="left">
License:
</th>
<td colspan="1" rowspan="1"
valign="top" align="left">
Commercial
</td>
</tr>
</table>


+ 6
- 0
src/etc/testcases/taskdefs/unzip.xml View File

@@ -27,6 +27,12 @@
<ant antfile="zip.xml" target="cleanup" />
</target>

<target name="testUncompressedZipTask">
<ant antfile="zip.xml" target="uncompressed-feather" />
<unzip src="asf-logo.gif.zip" dest="." />
<ant antfile="zip.xml" target="cleanup" />
</target>

<target name="realTest">
<unzip src="expected/asf-logo.gif.zip" dest="." />
</target>


+ 6
- 0
src/etc/testcases/taskdefs/zip.xml View File

@@ -55,6 +55,12 @@
includes="asf-logo.gif" />
</target>

<target name="uncompressed-feather">
<zip destFile="asf-logo.gif.zip"
basedir=".."
includes="asf-logo.gif" compress="false"/>
</target>

<!-- legacy attribute support -->
<target name="test8">
<zip zipfile="test8.zip" basedir="." >


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

@@ -977,15 +977,11 @@ public class Zip extends MatchingTask {
/*
* ZipOutputStream.putNextEntry expects the ZipEntry to
* know its size and the CRC sum before you start writing
* the data when using STORED mode.
* the data when using STORED mode - unless it is seekable.
*
* This forces us to process the data twice.
*
* In DEFLATED mode, it will take advantage of a Zip
* Version 2 feature where size can be stored after the
* data (as the data itself signals end of data).
*/
if (!doCompress) {
if (!zOut.isSeekable() && !doCompress) {
long size = 0;
CRC32 cal = new CRC32();
if (!in.markSupported()) {


+ 19
- 5
src/main/org/apache/tools/zip/ZipOutputStream.java View File

@@ -80,12 +80,12 @@ import java.util.zip.ZipException;
* file.</p>
*
* <p>If RandomAccessFile cannot be used, this implementation will use
* a Data Descriptor to store size and
* CRC information for DEFLATED entries, this means, you don't need to
* a Data Descriptor to store size and CRC information for {@link
* #DEFLATED DEFLATED} entries, this means, you don't need to
* calculate them yourself. Unfortunately this is not possible for
* the STORED method, here setting the CRC and uncompressed size
* information is required before {@link #putNextEntry putNextEntry}
* will be called.</p>
* the {@link #STORED STORED} method, here setting the CRC and
* uncompressed size information is required before {@link
* #putNextEntry putNextEntry} can be called.</p>
*
* @author Stefan Bodewig
* @author Richard Evans
@@ -290,6 +290,20 @@ public class ZipOutputStream extends FilterOutputStream {
}
}

/**
* Is this archive writing to a seekable stream (i.e. a random
* access file)?
*
* <p>For seekable streams, you don't need to calculate the CRC or
* uncompressed size for {@link #STORED STORED} entries before
* invoking {@link #putEntry putEntry}.
*
* @since 1.17
*/
public boolean isSeekable() {
return raf != null;
}

/**
* The encoding to use for filenames and the file comment.
*


+ 7
- 0
src/testcases/org/apache/tools/ant/taskdefs/UnzipTest.java View File

@@ -101,6 +101,13 @@ public class UnzipTest extends BuildFileTest {
project.resolveFile("asf-logo.gif")));
}
public void testTestUncompressedZipTask() throws java.io.IOException {
FileUtils fileUtils = FileUtils.newFileUtils();
executeTarget("testUncompressedZipTask");
assertTrue(fileUtils.contentEquals(project.resolveFile("../asf-logo.gif"),
project.resolveFile("asf-logo.gif")));
}
/*
* PR 11100
*/


Loading…
Cancel
Save