Browse Source

ZipEntry's copy constructor was incomplete

master
Stefan Bodewig 10 years ago
parent
commit
fa15b7c210
3 changed files with 24 additions and 1 deletions
  1. +11
    -1
      src/main/org/apache/tools/zip/GeneralPurposeBit.java
  2. +3
    -0
      src/main/org/apache/tools/zip/ZipEntry.java
  3. +10
    -0
      src/tests/junit/org/apache/tools/zip/ZipEntryTest.java

+ 11
- 1
src/main/org/apache/tools/zip/GeneralPurposeBit.java View File

@@ -23,7 +23,7 @@ package org.apache.tools.zip;
*
* @since Ant 1.9.0
*/
public final class GeneralPurposeBit {
public final class GeneralPurposeBit implements Cloneable {
/**
* Indicates that the file is encrypted.
*/
@@ -168,4 +168,14 @@ public final class GeneralPurposeBit {
&& g.languageEncodingFlag == languageEncodingFlag
&& g.dataDescriptorFlag == dataDescriptorFlag;
}

@Override
public Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException ex) {
// impossible
throw new RuntimeException("GeneralPurposeBit is not Cloneable?", ex);
}
}
}

+ 3
- 0
src/main/org/apache/tools/zip/ZipEntry.java View File

@@ -136,6 +136,9 @@ public class ZipEntry extends java.util.zip.ZipEntry implements Cloneable {
setInternalAttributes(entry.getInternalAttributes());
setExternalAttributes(entry.getExternalAttributes());
setExtraFields(entry.getExtraFields(true));
setPlatform(entry.platform);
setGeneralPurposeBit(entry.gpb == null ? null :
(GeneralPurposeBit) entry.gpb.clone());
}

/**


+ 10
- 0
src/tests/junit/org/apache/tools/zip/ZipEntryTest.java View File

@@ -215,4 +215,14 @@ public class ZipEntryTest {
ZipEntry entry2 = new ZipEntry("bar");
assertFalse(entry1.equals(entry2));
}

@Test
public void testCopyConstructor() throws Exception {
ZipEntry archiveEntry = new ZipEntry("fred");
archiveEntry.setUnixMode(0664);
archiveEntry.setMethod(ZipEntry.DEFLATED);
archiveEntry.getGeneralPurposeBit().useStrongEncryption(true);
ZipEntry copy = new ZipEntry(archiveEntry);
assertEquals(archiveEntry, copy);
}
}

Loading…
Cancel
Save