001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.tools.zip;
020:
021: /**
022: * Simple placeholder for all those extra fields we don't want to deal
023: * with.
024: *
025: * <p>Assumes local file data and central directory entries are
026: * identical - unless told the opposite.</p>
027: *
028: */
029: public class UnrecognizedExtraField implements ZipExtraField {
030:
031: /**
032: * The Header-ID.
033: *
034: * @since 1.1
035: */
036: private ZipShort headerId;
037:
038: /**
039: * Set the header id.
040: * @param headerId the header id to use
041: */
042: public void setHeaderId(ZipShort headerId) {
043: this .headerId = headerId;
044: }
045:
046: /**
047: * Get the header id.
048: * @return the header id
049: */
050: public ZipShort getHeaderId() {
051: return headerId;
052: }
053:
054: /**
055: * Extra field data in local file data - without
056: * Header-ID or length specifier.
057: *
058: * @since 1.1
059: */
060: private byte[] localData;
061:
062: /**
063: * Set the extra field data in the local file data -
064: * without Header-ID or length specifier.
065: * @param data the field data to use
066: */
067: public void setLocalFileDataData(byte[] data) {
068: localData = data;
069: }
070:
071: /**
072: * Get the length of the local data.
073: * @return the length of the local data
074: */
075: public ZipShort getLocalFileDataLength() {
076: return new ZipShort(localData.length);
077: }
078:
079: /**
080: * Get the local data.
081: * @return the local data
082: */
083: public byte[] getLocalFileDataData() {
084: return localData;
085: }
086:
087: /**
088: * Extra field data in central directory - without
089: * Header-ID or length specifier.
090: *
091: * @since 1.1
092: */
093: private byte[] centralData;
094:
095: /**
096: * Set the extra field data in central directory.
097: * @param data the data to use
098: */
099: public void setCentralDirectoryData(byte[] data) {
100: centralData = data;
101: }
102:
103: /**
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
107: */
108: public ZipShort getCentralDirectoryLength() {
109: if (centralData != null) {
110: return new ZipShort(centralData.length);
111: }
112: return getLocalFileDataLength();
113: }
114:
115: /**
116: * Get the central data.
117: * @return the central data if present, else return the local file data
118: */
119: public byte[] getCentralDirectoryData() {
120: if (centralData != null) {
121: return centralData;
122: }
123: return getLocalFileDataData();
124: }
125:
126: /**
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)
131: */
132: public void parseFromLocalFileData(byte[] data, int offset,
133: int length) {
134: byte[] tmp = new byte[length];
135: System.arraycopy(data, offset, tmp, 0, length);
136: setLocalFileDataData(tmp);
137: }
138: }
|