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 */
019package org.apache.commons.compress.archivers.zip;
020
021import 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 */
032public interface ZipExtraField {
033    /**
034     * Size of an extra field header (id + length).
035     * @since 1.14
036     */
037    int EXTRAFIELD_HEADER_SIZE = 4;
038
039    /**
040     * The actual data to put into central directory - without Header-ID or
041     * length specifier.
042     * @return the data
043     */
044    byte[] getCentralDirectoryData();
045
046    /**
047     * Length of the extra field in the central directory - without
048     * Header-ID or length specifier.
049     * @return the length of the field in the central directory
050     */
051    ZipShort getCentralDirectoryLength();
052
053    /**
054     * The Header-ID.
055     *
056     * @return The HeaderId value
057     */
058    ZipShort getHeaderId();
059
060    /**
061     * The actual data to put into local file data - without Header-ID
062     * or length specifier.
063     * @return the data
064     */
065    byte[] getLocalFileDataData();
066
067    /**
068     * Length of the extra field in the local file data - without
069     * Header-ID or length specifier.
070     * @return the length of the field in the local file data
071     */
072    ZipShort getLocalFileDataLength();
073
074    /**
075     * Populate data from this array as if it was in central directory data.
076     *
077     * @param buffer the buffer to read data from
078     * @param offset offset into buffer to read data
079     * @param length the length of data
080     * @throws ZipException on error
081     */
082    void parseFromCentralDirectoryData(byte[] buffer, int offset, int length)
083        throws ZipException;
084
085    /**
086     * Populate data from this array as if it was in local file data.
087     *
088     * @param buffer the buffer to read data from
089     * @param offset offset into buffer to read data
090     * @param length the length of data
091     * @throws ZipException on error
092     */
093    void parseFromLocalFileData(byte[] buffer, int offset, int length)
094        throws ZipException;
095}