diff --git a/src/main/org/apache/tools/ant/taskdefs/Zip.java b/src/main/org/apache/tools/ant/taskdefs/Zip.java index 93d1a905f..70436fb15 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Zip.java +++ b/src/main/org/apache/tools/ant/taskdefs/Zip.java @@ -351,8 +351,8 @@ public class Zip extends MatchingTask { } } } - } catch (IOException ioe) { - String msg = "Problem creating " + archiveType + ": " + ioe.getMessage(); + } catch (Throwable t) { + String msg = "Problem creating " + archiveType + ": " + t.getMessage(); // delete a bogus ZIP file if (!zipFile.delete()) { @@ -366,7 +366,7 @@ public class Zip extends MatchingTask { } } - throw new BuildException(msg, ioe, location); + throw new BuildException(msg, t, location); } finally { cleanUp(); } diff --git a/src/main/org/apache/tools/zip/ZipOutputStream.java b/src/main/org/apache/tools/zip/ZipOutputStream.java index 733fb43ac..a281301fe 100644 --- a/src/main/org/apache/tools/zip/ZipOutputStream.java +++ b/src/main/org/apache/tools/zip/ZipOutputStream.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2001 The Apache Software Foundation. All rights + * Copyright (c) 2001-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -105,6 +105,14 @@ public class ZipOutputStream extends DeflaterOutputStream { */ private int level = Deflater.DEFAULT_COMPRESSION; + /** + * Has the compression level changed when compared to the last + * entry? + * + * @since 1.5 + */ + private boolean hasCompressionLevelChanged = false; + /** * Default compression method for next entry. * @@ -331,8 +339,9 @@ public class ZipOutputStream extends DeflaterOutputStream { throw new ZipException("crc checksum is required for STORED method"); } entry.setComprSize(entry.getSize()); - } else { + } else if (hasCompressionLevelChanged) { def.setLevel(level); + hasCompressionLevelChanged = false; } writeLocalFileHeader(entry); } @@ -354,6 +363,7 @@ public class ZipOutputStream extends DeflaterOutputStream { * @since 1.1 */ public void setLevel(int level) { + hasCompressionLevelChanged = (this.level != level); this.level = level; }