KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > zip > UnrecognizedExtraField


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
23  * with.
24  *
25  * <p>Assumes local file data and central directory entries are
26  * identical - unless told the opposite.</p>
27  *
28  */

29 public class UnrecognizedExtraField implements ZipExtraField {
30
31     /**
32      * The Header-ID.
33      *
34      * @since 1.1
35      */

36     private ZipShort headerId;
37
38     /**
39      * Set the header id.
40      * @param headerId the header id to use
41      */

42     public void setHeaderId(ZipShort headerId) {
43         this.headerId = headerId;
44     }
45
46     /**
47      * Get the header id.
48      * @return the header id
49      */

50     public ZipShort getHeaderId() {
51         return headerId;
52     }
53
54     /**
55      * Extra field data in local file data - without
56      * Header-ID or length specifier.
57      *
58      * @since 1.1
59      */

60     private byte[] localData;
61
62     /**
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
66      */

67     public void setLocalFileDataData(byte[] data) {
68         localData = data;
69     }
70
71     /**
72      * Get the length of the local data.
73      * @return the length of the local data
74      */

75     public ZipShort getLocalFileDataLength() {
76         return new ZipShort(localData.length);
77     }
78
79     /**
80      * Get the local data.
81      * @return the local data
82      */

83     public byte[] getLocalFileDataData() {
84         return localData;
85     }
86
87     /**
88      * Extra field data in central directory - without
89      * Header-ID or length specifier.
90      *
91      * @since 1.1
92      */

93     private byte[] centralData;
94
95     /**
96      * Set the extra field data in central directory.
97      * @param data the data to use
98      */

99     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, int length) {
133         byte[] tmp = new byte[length];
134         System.arraycopy(data, offset, tmp, 0, length);
135         setLocalFileDataData(tmp);
136     }
137 }
138
Popular Tags