Search in sources :

Example 1 with Zip64ExtendedInformationExtraField

use of org.apache.tools.zip.Zip64ExtendedInformationExtraField in project ant by apache.

the class ZipExtraFieldTest method testExtraField.

private void testExtraField(Zip testInstance, boolean expectZip64) throws IOException {
    File f = File.createTempFile("ziptest", ".zip");
    f.delete();
    ZipFile zf = null;
    try {
        testInstance.setDestFile(f);
        final ZipResource r = new ZipResource() {

            public String getName() {
                return "x";
            }

            public boolean isExists() {
                return true;
            }

            public boolean isDirectory() {
                return false;
            }

            public long getLastModified() {
                return 1;
            }

            public InputStream getInputStream() {
                return new ByteArrayInputStream(new byte[0]);
            }

            public ZipExtraField[] getExtraFields() {
                return new ZipExtraField[] { new JarMarker() };
            }
        };
        testInstance.add(new ResourceCollection() {

            public boolean isFilesystemOnly() {
                return false;
            }

            public int size() {
                return 1;
            }

            public Iterator<Resource> iterator() {
                return Collections.<Resource>singleton(r).iterator();
            }
        });
        testInstance.execute();
        zf = new ZipFile(f);
        ZipEntry ze = zf.getEntry("x");
        assertNotNull(ze);
        assertEquals(expectZip64 ? 2 : 1, ze.getExtraFields().length);
        assertTrue(ze.getExtraFields()[0] instanceof JarMarker);
        if (expectZip64) {
            assertTrue(ze.getExtraFields()[1] instanceof Zip64ExtendedInformationExtraField);
        }
    } finally {
        ZipFile.closeQuietly(zf);
        if (f.exists()) {
            f.delete();
        }
    }
}
Also used : ZipExtraField(org.apache.tools.zip.ZipExtraField) ZipResource(org.apache.tools.ant.types.resources.ZipResource) ZipFile(org.apache.tools.zip.ZipFile) JarMarker(org.apache.tools.zip.JarMarker) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipEntry(org.apache.tools.zip.ZipEntry) Iterator(java.util.Iterator) Resource(org.apache.tools.ant.types.Resource) ZipResource(org.apache.tools.ant.types.resources.ZipResource) ZipFile(org.apache.tools.zip.ZipFile) File(java.io.File) ResourceCollection(org.apache.tools.ant.types.ResourceCollection) Zip64ExtendedInformationExtraField(org.apache.tools.zip.Zip64ExtendedInformationExtraField)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 Iterator (java.util.Iterator)1 Resource (org.apache.tools.ant.types.Resource)1 ResourceCollection (org.apache.tools.ant.types.ResourceCollection)1 ZipResource (org.apache.tools.ant.types.resources.ZipResource)1 JarMarker (org.apache.tools.zip.JarMarker)1 Zip64ExtendedInformationExtraField (org.apache.tools.zip.Zip64ExtendedInformationExtraField)1 ZipEntry (org.apache.tools.zip.ZipEntry)1 ZipExtraField (org.apache.tools.zip.ZipExtraField)1 ZipFile (org.apache.tools.zip.ZipFile)1