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