    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    /**
    029     * Creates an instance of ZipExtraField for the given id.
    030     * <p>
    031     * A good default implementation would be {@link ExtraFieldUtils#createExtraField}.
    032     * </p>
    033     *
    034     * @param headerId the id for the extra field
    035     * @return an instance of ZipExtraField, must not be {@code null}
    036     * @throws ZipException           if an error occurs
    037     * @throws InstantiationException if unable to instantiate the class, not thrown by Commons Compress.
    038     * @throws IllegalAccessException if not allowed to instantiate the class, not thrown by Commons Compress.
    039     */
    040    ZipExtraField createExtraField(ZipShort headerId) throws ZipException, InstantiationException, IllegalAccessException;
    041
    042    /**
    043     * Fills in the extra field data for a single extra field.
    044     * <p>
    045     * A good default implementation would be {@link ExtraFieldUtils#fillExtraField}.
    046     * </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 file header. If this is false then the data is part if the central directory header extra
    053     *              data.
    054     * @return the filled field. Usually this is the same as {@code
    055     * field} but it could be a replacement extra field as well. Must not be {@code null}.
    056     * @throws ZipException if an error occurs
    057     */
    058    ZipExtraField fill(ZipExtraField field, byte[] data, int off, int len, boolean local) throws ZipException;
    059}