001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one or more
003 *  contributor license agreements.  See the NOTICE file distributed with
004 *  this work for additional information regarding copyright ownership.
005 *  The ASF licenses this file to You under the Apache License, Version 2.0
006 *  (the "License"); you may not use this file except in compliance with
007 *  the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 *  Unless required by applicable law or agreed to in writing, software
012 *  distributed under the License is distributed on an "AS IS" BASIS,
013 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 *  See the License for the specific language governing permissions and
015 *  limitations under the License.
016 */
017package org.apache.commons.compress.archivers.zip;
018
019import java.util.zip.ZipException;
020
021/**
022 * Controls details of parsing ZIP extra fields.
023 *
024 * @since 1.19
025 */
026public interface ExtraFieldParsingBehavior extends UnparseableExtraFieldBehavior {
027    /**
028     * Creates an instance of ZipExtraField for the given id.
029     *
030     * <p>A good default implementation would be {@link
031     * ExtraFieldUtils#createExtraField}.</p>
032     *
033     * @param headerId the id for the extra field
034     * @return an instance of ZipExtraField, must not be {@code null}
035     * @throws ZipException if an error occurs
036     * @throws InstantiationException if unable to instantiate the class
037     * @throws IllegalAccessException if not allowed to instantiate the class
038     */
039    ZipExtraField createExtraField(final ZipShort headerId)
040        throws ZipException, InstantiationException, IllegalAccessException;
041
042    /**
043     * Fills in the extra field data for a single extra field.
044     *
045     * <p>A good default implementation would be {@link
046     * ExtraFieldUtils#fillExtraField}.</p>
047     *
048     * @param field the extra field instance to fill
049     * @param data the array of extra field data
050     * @param off offset into data where this field's data starts
051     * @param len the length of this field's data
052     * @param local whether the extra field data stems from the local
053     * file header. If this is false then the data is part if the
054     * central directory header extra data.
055     * @return the filled field. Usually this is the same as {@code
056     * field} but it could be a replacement extra field as well. Must
057     * not be {@code null}.
058     * @throws ZipException if an error occurs
059     */
060    ZipExtraField fill(ZipExtraField field, byte[] data, int off, int len, boolean local)
061        throws ZipException;
062}