• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements.  See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership.  The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License.  You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied.  See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 package org.apache.commons.compress.archivers.zip;
20 
21 import java.util.zip.ZipException;
22 
23 /**
24  * General format of extra field data.
25  *
26  * <p>Extra fields usually appear twice per file, once in the local
27  * file data and once in the central directory.  Usually they are the
28  * same, but they don't have to be.  {@link
29  * java.util.zip.ZipOutputStream java.util.zip.ZipOutputStream} will
30  * only use the local file data in both places.</p>
31  *
32  */
33 public interface ZipExtraField {
34     /**
35      * Size of an extra field field header (id + length).
36      * @since 1.14
37      */
38     int EXTRAFIELD_HEADER_SIZE = 4;
39 
40     /**
41      * The Header-ID.
42      *
43      * @return The HeaderId value
44      */
getHeaderId()45     ZipShort getHeaderId();
46 
47     /**
48      * Length of the extra field in the local file data - without
49      * Header-ID or length specifier.
50      * @return the length of the field in the local file data
51      */
getLocalFileDataLength()52     ZipShort getLocalFileDataLength();
53 
54     /**
55      * Length of the extra field in the central directory - without
56      * Header-ID or length specifier.
57      * @return the length of the field in the central directory
58      */
getCentralDirectoryLength()59     ZipShort getCentralDirectoryLength();
60 
61     /**
62      * The actual data to put into local file data - without Header-ID
63      * or length specifier.
64      * @return the data
65      */
getLocalFileDataData()66     byte[] getLocalFileDataData();
67 
68     /**
69      * The actual data to put into central directory - without Header-ID or
70      * length specifier.
71      * @return the data
72      */
getCentralDirectoryData()73     byte[] getCentralDirectoryData();
74 
75     /**
76      * Populate data from this array as if it was in local file data.
77      *
78      * @param buffer the buffer to read data from
79      * @param offset offset into buffer to read data
80      * @param length the length of data
81      * @throws ZipException on error
82      */
parseFromLocalFileData(byte[] buffer, int offset, int length)83     void parseFromLocalFileData(byte[] buffer, int offset, int length)
84         throws ZipException;
85 
86     /**
87      * Populate data from this array as if it was in central directory data.
88      *
89      * @param buffer the buffer to read data from
90      * @param offset offset into buffer to read data
91      * @param length the length of data
92      * @throws ZipException on error
93      */
parseFromCentralDirectoryData(byte[] buffer, int offset, int length)94     void parseFromCentralDirectoryData(byte[] buffer, int offset, int length)
95         throws ZipException;
96 }
97