| career | drupal | java | mac | mysql | perl | scala | uml | unix  

Ant example source code file (

This example Ant source code file ( is included in the "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Ant tags/keywords

asiextrafield, testcase, unrecognizedextrafield, unrecognizedextrafield, zipentry, zipentry, zipentrytest, zipentrytest, zipextrafield, zipshort, zipshort

The source code

 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.


import junit.framework.TestCase;

 * JUnit 3 testcases for
public class ZipEntryTest extends TestCase {

    public ZipEntryTest(String name) {

     * test handling of extra fields
     * @since 1.1
    public void testExtraFields() {
        AsiExtraField a = new AsiExtraField();
        UnrecognizedExtraField u = new UnrecognizedExtraField();
        u.setHeaderId(new ZipShort(1));
        u.setLocalFileDataData(new byte[0]);

        ZipEntry ze = new ZipEntry("test/");
        ze.setExtraFields(new ZipExtraField[] {a, u});
        byte[] data1 = ze.getExtra();
        ZipExtraField[] result = ze.getExtraFields();
        assertEquals("first pass", 2, result.length);
        assertSame(a, result[0]);
        assertSame(u, result[1]);

        UnrecognizedExtraField u2 = new UnrecognizedExtraField();
        u2.setHeaderId(new ZipShort(1));
        u2.setLocalFileDataData(new byte[] {1});

        byte[] data2 = ze.getExtra();
        result = ze.getExtraFields();
        assertEquals("second pass", 2, result.length);
        assertSame(a, result[0]);
        assertSame(u2, result[1]);
        assertEquals("length second pass", data1.length+1, data2.length);

        UnrecognizedExtraField u3 = new UnrecognizedExtraField();
        u3.setHeaderId(new ZipShort(2));
        u3.setLocalFileDataData(new byte[] {1});
        result = ze.getExtraFields();
        assertEquals("third pass", 3, result.length);

        ze.removeExtraField(new ZipShort(1));
        byte[] data3 = ze.getExtra();
        result = ze.getExtraFields();
        assertEquals("fourth pass", 2, result.length);
        assertSame(a, result[0]);
        assertSame(u3, result[1]);
        assertEquals("length fourth pass", data2.length, data3.length);

        try {
            ze.removeExtraField(new ZipShort(1));
            fail("should be no such element");
        } catch (java.util.NoSuchElementException nse) {

    public void testUnixMode() {
        ZipEntry ze = new ZipEntry("foo");
        assertEquals(0, ze.getPlatform());
        assertEquals(3, ze.getPlatform());
                     (ze.getExternalAttributes() >> 16) & 0xFFFF);
        assertEquals(0, ze.getExternalAttributes()  & 0xFFFF);

        assertEquals(3, ze.getPlatform());
                     (ze.getExternalAttributes() >> 16) & 0xFFFF);
        assertEquals(1, ze.getExternalAttributes()  & 0xFFFF);

        ze = new ZipEntry("foo/");
        assertEquals(0, ze.getPlatform());
        assertEquals(3, ze.getPlatform());
                     (ze.getExternalAttributes() >> 16) & 0xFFFF);
        assertEquals(0x10, ze.getExternalAttributes()  & 0xFFFF);

        assertEquals(3, ze.getPlatform());
                     (ze.getExternalAttributes() >> 16) & 0xFFFF);
        assertEquals(0x11, ze.getExternalAttributes()  & 0xFFFF);


Other Ant examples (source code examples)

Here is a short list of links related to this Ant source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller


new blog posts


Copyright 1998-2021 Alvin Alexander,
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.