applied LGPLv3 and source code formatting.
[vamsas.git] / src / org / apache / tools / zip / UnrecognizedExtraField.java
1 /*
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  */
18
19 package org.apache.tools.zip;
20
21 /**
22  * Simple placeholder for all those extra fields we don't want to deal with.
23  * 
24  * <p>
25  * Assumes local file data and central directory entries are identical - unless
26  * told the opposite.
27  * </p>
28  * 
29  */
30 public class UnrecognizedExtraField implements ZipExtraField {
31
32   /**
33    * The Header-ID.
34    * 
35    * @since 1.1
36    */
37   private ZipShort headerId;
38
39   /**
40    * Set the header id.
41    * 
42    * @param headerId
43    *          the header id to use
44    */
45   public void setHeaderId(ZipShort headerId) {
46     this.headerId = headerId;
47   }
48
49   /**
50    * Get the header id.
51    * 
52    * @return the header id
53    */
54   public ZipShort getHeaderId() {
55     return headerId;
56   }
57
58   /**
59    * Extra field data in local file data - without Header-ID or length
60    * specifier.
61    * 
62    * @since 1.1
63    */
64   private byte[] localData;
65
66   /**
67    * Set the extra field data in the local file data - without Header-ID or
68    * length specifier.
69    * 
70    * @param data
71    *          the field data to use
72    */
73   public void setLocalFileDataData(byte[] data) {
74     localData = data;
75   }
76
77   /**
78    * Get the length of the local data.
79    * 
80    * @return the length of the local data
81    */
82   public ZipShort getLocalFileDataLength() {
83     return new ZipShort(localData.length);
84   }
85
86   /**
87    * Get the local data.
88    * 
89    * @return the local data
90    */
91   public byte[] getLocalFileDataData() {
92     return localData;
93   }
94
95   /**
96    * Extra field data in central directory - without Header-ID or length
97    * specifier.
98    * 
99    * @since 1.1
100    */
101   private byte[] centralData;
102
103   /**
104    * Set the extra field data in central directory.
105    * 
106    * @param data
107    *          the data to use
108    */
109   public void setCentralDirectoryData(byte[] data) {
110     centralData = data;
111   }
112
113   /**
114    * Get the central data length. If there is no central data, get the local
115    * file data length.
116    * 
117    * @return the central data length
118    */
119   public ZipShort getCentralDirectoryLength() {
120     if (centralData != null) {
121       return new ZipShort(centralData.length);
122     }
123     return getLocalFileDataLength();
124   }
125
126   /**
127    * Get the central data.
128    * 
129    * @return the central data if present, else return the local file data
130    */
131   public byte[] getCentralDirectoryData() {
132     if (centralData != null) {
133       return centralData;
134     }
135     return getLocalFileDataData();
136   }
137
138   /**
139    * @param data
140    *          the array of bytes.
141    * @param offset
142    *          the source location in the data array.
143    * @param length
144    *          the number of bytes to use in the data array.
145    * @see ZipExtraField#parseFromLocalFileData(byte[], int, int)
146    */
147   public void parseFromLocalFileData(byte[] data, int offset, int length) {
148     byte[] tmp = new byte[length];
149     System.arraycopy(data, offset, tmp, 0, length);
150     setLocalFileDataData(tmp);
151   }
152 }