001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements.  See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership.  The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the
007     * "License"); you may not use this file except in compliance
008     * with the License.  You may obtain a copy of the License at
009     *
010     * http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing,
013     * software distributed under the License is distributed on an
014     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015     * KIND, either express or implied.  See the License for the
016     * specific language governing permissions and limitations
017     * under the License.
018     */
019    package org.apache.commons.compress.archivers.zip;
020    
021    import java.util.zip.ZipException;
022    
023    /**
024     * General format of extra field data.
025     *
026     * <p>Extra fields usually appear twice per file, once in the local
027     * file data and once in the central directory.  Usually they are the
028     * same, but they don't have to be.  {@link
029     * java.util.zip.ZipOutputStream java.util.zip.ZipOutputStream} will
030     * only use the local file data in both places.</p>
031     *
032     */
033    public interface ZipExtraField {
034        /**
035         * The Header-ID.
036         *
037         * @return The HeaderId value
038         */
039        ZipShort getHeaderId();
040    
041        /**
042         * Length of the extra field in the local file data - without
043         * Header-ID or length specifier.
044         * @return the length of the field in the local file data
045         */
046        ZipShort getLocalFileDataLength();
047    
048        /**
049         * Length of the extra field in the central directory - without
050         * Header-ID or length specifier.
051         * @return the length of the field in the central directory
052         */
053        ZipShort getCentralDirectoryLength();
054    
055        /**
056         * The actual data to put into local file data - without Header-ID
057         * or length specifier.
058         * @return the data
059         */
060        byte[] getLocalFileDataData();
061    
062        /**
063         * The actual data to put into central directory - without Header-ID or
064         * length specifier.
065         * @return the data
066         */
067        byte[] getCentralDirectoryData();
068    
069        /**
070         * Populate data from this array as if it was in local file data.
071         *
072         * @param buffer the buffer to read data from
073         * @param offset offset into buffer to read data
074         * @param length the length of data
075         * @exception ZipException on error
076         */
077        void parseFromLocalFileData(byte[] buffer, int offset, int length)
078            throws ZipException;
079    
080        /**
081         * Populate data from this array as if it was in central directory data.
082         *
083         * @param buffer the buffer to read data from
084         * @param offset offset into buffer to read data
085         * @param length the length of data
086         * @exception ZipException on error
087         */
088        void parseFromCentralDirectoryData(byte[] buffer, int offset, int length)
089            throws ZipException;
090    }