2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 package org.apache.tools.zip;
22 * Simple placeholder for all those extra fields we don't want to deal
25 * <p>Assumes local file data and central directory entries are
26 * identical - unless told the opposite.</p>
29 public class UnrecognizedExtraField implements ZipExtraField {
36 private ZipShort headerId;
40 * @param headerId the header id to use
42 public void setHeaderId(ZipShort headerId) {
43 this.headerId = headerId;
48 * @return the header id
50 public ZipShort getHeaderId() {
55 * Extra field data in local file data - without
56 * Header-ID or length specifier.
60 private byte[] localData;
63 * Set the extra field data in the local file data -
64 * without Header-ID or length specifier.
65 * @param data the field data to use
67 public void setLocalFileDataData(byte[] data) {
72 * Get the length of the local data.
73 * @return the length of the local data
75 public ZipShort getLocalFileDataLength() {
76 return new ZipShort(localData.length);
81 * @return the local data
83 public byte[] getLocalFileDataData() {
88 * Extra field data in central directory - without
89 * Header-ID or length specifier.
93 private byte[] centralData;
96 * Set the extra field data in central directory.
97 * @param data the data to use
99 public void setCentralDirectoryData(byte[] data) {
104 * Get the central data length.
105 * If there is no central data, get the local file data length.
106 * @return the central data length
108 public ZipShort getCentralDirectoryLength() {
109 if (centralData != null) {
110 return new ZipShort(centralData.length);
112 return getLocalFileDataLength();
116 * Get the central data.
117 * @return the central data if present, else return the local file data
119 public byte[] getCentralDirectoryData() {
120 if (centralData != null) {
123 return getLocalFileDataData();
127 * @param data the array of bytes.
128 * @param offset the source location in the data array.
129 * @param length the number of bytes to use in the data array.
130 * @see ZipExtraField#parseFromLocalFileData(byte[], int, int)
132 public void parseFromLocalFileData(byte[] data, int offset, int length) {
133 byte[] tmp = new byte[length];
134 System.arraycopy(data, offset, tmp, 0, length);
135 setLocalFileDataData(tmp);