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> 027 * Extra fields usually appear twice per file, once in the local file data and once in the central directory. Usually they are the same, but they don't have to 028 * be. {@link java.util.zip.ZipOutputStream java.util.zip.ZipOutputStream} will only use the local file data in both places. 029 * </p> 030 */ 031public interface ZipExtraField { 032 /** 033 * Size of an extra field header (id + length). 034 * 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 length specifier. 041 * 042 * @return the data 043 */ 044 byte[] getCentralDirectoryData(); 045 046 /** 047 * Length of the extra field in the central directory - without Header-ID or length specifier. 048 * 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 or length specifier. 062 * 063 * @return the data 064 */ 065 byte[] getLocalFileDataData(); 066 067 /** 068 * Length of the extra field in the local file data - without Header-ID or length specifier. 069 * 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) throws ZipException; 083 084 /** 085 * Populate data from this array as if it was in local file data. 086 * 087 * @param buffer the buffer to read data from 088 * @param offset offset into buffer to read data 089 * @param length the length of data 090 * @throws ZipException on error 091 */ 092 void parseFromLocalFileData(byte[] buffer, int offset, int length) throws ZipException; 093}