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>
27 * 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
28 * be. {@link java.util.zip.ZipOutputStream java.util.zip.ZipOutputStream} will only use the local file data in both places.
29 * </p>
30 */
31 public interface ZipExtraField {
32 /**
33 * Size of an extra field header (id + length).
34 *
35 * @since 1.14
36 */
37 int EXTRAFIELD_HEADER_SIZE = 4;
38
39 /**
40 * The actual data to put into central directory - without Header-ID or length specifier.
41 *
42 * @return the data
43 */
44 byte[] getCentralDirectoryData();
45
46 /**
47 * Length of the extra field in the central directory - without Header-ID or length specifier.
48 *
49 * @return the length of the field in the central directory
50 */
51 ZipShort getCentralDirectoryLength();
52
53 /**
54 * The Header-ID.
55 *
56 * @return The HeaderId value
57 */
58 ZipShort getHeaderId();
59
60 /**
61 * The actual data to put into local file data - without Header-ID or length specifier.
62 *
63 * @return the data
64 */
65 byte[] getLocalFileDataData();
66
67 /**
68 * Length of the extra field in the local file data - without Header-ID or length specifier.
69 *
70 * @return the length of the field in the local file data
71 */
72 ZipShort getLocalFileDataLength();
73
74 /**
75 * Populate data from this array as if it was in central directory data.
76 *
77 * @param buffer the buffer to read data from
78 * @param offset offset into buffer to read data
79 * @param length the length of data
80 * @throws ZipException on error
81 */
82 void parseFromCentralDirectoryData(byte[] buffer, int offset, int length) throws ZipException;
83
84 /**
85 * Populate data from this array as if it was in local file data.
86 *
87 * @param buffer the buffer to read data from
88 * @param offset offset into buffer to read data
89 * @param length the length of data
90 * @throws ZipException on error
91 */
92 void parseFromLocalFileData(byte[] buffer, int offset, int length) throws ZipException;
93 }
94