~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/ikvm/openjdk/java/util/zip/ZipEntry.java

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ZipEntry.java --
 
2
   Copyright (C) 2001, 2002, 2004, 2005, 2011 Free Software Foundation, Inc.
 
3
 
 
4
This file is part of GNU Classpath.
 
5
 
 
6
GNU Classpath is free software; you can redistribute it and/or modify
 
7
it under the terms of the GNU General Public License as published by
 
8
the Free Software Foundation; either version 2, or (at your option)
 
9
any later version.
 
10
 
 
11
GNU Classpath is distributed in the hope that it will be useful, but
 
12
WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
General Public License for more details.
 
15
 
 
16
You should have received a copy of the GNU General Public License
 
17
along with GNU Classpath; see the file COPYING.  If not, write to the
 
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
19
02110-1301 USA.
 
20
 
 
21
Linking this library statically or dynamically with other modules is
 
22
making a combined work based on this library.  Thus, the terms and
 
23
conditions of the GNU General Public License cover the whole
 
24
combination.
 
25
 
 
26
As a special exception, the copyright holders of this library give you
 
27
permission to link this library with independent modules to produce an
 
28
executable, regardless of the license terms of these independent
 
29
modules, and to copy and distribute the resulting executable under
 
30
terms of your choice, provided that you also meet, for each linked
 
31
independent module, the terms and conditions of the license of that
 
32
module.  An independent module is a module which is not derived from
 
33
or based on this library.  If you modify this library, you may extend
 
34
this exception to your version of the library, but you are not
 
35
obligated to do so.  If you do not wish to do so, delete this
 
36
exception statement from your version. */
 
37
 
 
38
 
 
39
package java.util.zip;
 
40
 
 
41
import java.util.Date;
 
42
 
 
43
/**
 
44
 * This class represents a member of a zip archive.  ZipFile and
 
45
 * ZipInputStream will give you instances of this class as information
 
46
 * about the members in an archive.  On the other hand ZipOutputStream
 
47
 * needs an instance of this class to create a new member.
 
48
 *
 
49
 * @author Jochen Hoenicke 
 
50
 */
 
51
public class ZipEntry implements ZipConstants, Cloneable
 
52
{
 
53
    String name;
 
54
    long time = -1;
 
55
    long crc = -1;
 
56
    long size = -1;
 
57
    long csize = -1;
 
58
    int method = -1;
 
59
    int flag;
 
60
    byte[] extra;
 
61
    String comment;
 
62
 
 
63
    long offset;             /* used by ZipFile */
 
64
 
 
65
    /**
 
66
     * Compression method.  This method doesn't compress at all.
 
67
     */
 
68
    public static final int STORED = 0;
 
69
    /**
 
70
     * Compression method.  This method uses the Deflater.
 
71
     */
 
72
    public static final int DEFLATED = 8;
 
73
 
 
74
    /**
 
75
     * Creates a zip entry with the given name.
 
76
     * @param name the name. May include directory components separated
 
77
     * by '/'.
 
78
     *
 
79
     * @exception NullPointerException when name is null.
 
80
     * @exception IllegalArgumentException when name is bigger then 65535 chars.
 
81
     */
 
82
    public ZipEntry(String name)
 
83
    {
 
84
        int length = name.length();
 
85
        if (length > 65535)
 
86
            throw new IllegalArgumentException("name length is " + length);
 
87
        this.name = name;
 
88
    }
 
89
 
 
90
    /**
 
91
     * Creates a copy of the given zip entry.
 
92
     * @param e the entry to copy.
 
93
     */
 
94
    public ZipEntry(ZipEntry e)
 
95
    {
 
96
        name = e.name;
 
97
        time = e.time;
 
98
        crc = e.crc;
 
99
        size = e.size;
 
100
        csize = e.csize;
 
101
        method = e.method;
 
102
        flag = e.flag;
 
103
        extra = e.extra;
 
104
        comment = e.comment;
 
105
    }
 
106
 
 
107
    ZipEntry()
 
108
    {
 
109
    }
 
110
 
 
111
    /**
 
112
     * Creates a copy of this zip entry.
 
113
     */
 
114
    /**
 
115
     * Clones the entry.
 
116
     */
 
117
    public Object clone()
 
118
    {
 
119
        try
 
120
        {
 
121
            // The JCL says that the `extra' field is also copied.
 
122
            ZipEntry clone = (ZipEntry)super.clone();
 
123
            if (extra != null)
 
124
                clone.extra = (byte[])extra.clone();
 
125
            return clone;
 
126
        }
 
127
        catch (CloneNotSupportedException ex)
 
128
        {
 
129
            throw new InternalError();
 
130
        }
 
131
    }
 
132
 
 
133
    /**
 
134
     * Returns the entry name.  The path components in the entry are
 
135
     * always separated by slashes ('/').  
 
136
     */
 
137
    public String getName()
 
138
    {
 
139
        return name;
 
140
    }
 
141
 
 
142
    /**
 
143
     * Sets the time of last modification of the entry.
 
144
     * @time the time of last modification of the entry.
 
145
     */
 
146
    public void setTime(long time)
 
147
    {
 
148
        Date d = new Date(time);
 
149
        if (d.getYear() < 80)
 
150
        {
 
151
            d = new Date(80, 0, 1);
 
152
        }
 
153
        this.time = ((d.getYear() - 80) << 25)
 
154
            | ((d.getMonth() + 1) << 21)
 
155
            | (d.getDate() << 16)
 
156
            | (d.getHours() << 11)
 
157
            | (d.getMinutes() << 5)
 
158
            | (d.getSeconds() >> 1);
 
159
    }
 
160
 
 
161
    /**
 
162
     * Gets the time of last modification of the entry.
 
163
     * @return the time of last modification of the entry, or -1 if unknown.
 
164
     */
 
165
    public long getTime()
 
166
    {
 
167
        if (time == -1)
 
168
        {
 
169
            return -1;
 
170
        }
 
171
        Date d = new Date((int)(((time >> 25) & 0x7f) + 80),
 
172
                  (int)(((time >> 21) & 0x0f) - 1),
 
173
                  (int)((time >> 16) & 0x1f),
 
174
                  (int)((time >> 11) & 0x1f),
 
175
                  (int)((time >> 5) & 0x3f),
 
176
                  (int)((time << 1) & 0x3e));
 
177
        return d.getTime();
 
178
    }
 
179
 
 
180
    /**
 
181
     * Sets the size of the uncompressed data.
 
182
     * @exception IllegalArgumentException if size is negative.
 
183
     */
 
184
    public void setSize(long size)
 
185
    {
 
186
        if (size < 0)
 
187
            throw new IllegalArgumentException();
 
188
        this.size = size;
 
189
    }
 
190
 
 
191
    /**
 
192
     * Gets the size of the uncompressed data.
 
193
     * @return the size or -1 if unknown.
 
194
     */
 
195
    public long getSize()
 
196
    {
 
197
        return size;
 
198
    }
 
199
 
 
200
    /**
 
201
     * Sets the size of the compressed data.
 
202
     */
 
203
    public void setCompressedSize(long csize)
 
204
    {
 
205
        this.csize = csize;
 
206
    }
 
207
 
 
208
    /**
 
209
     * Gets the size of the compressed data.
 
210
     * @return the size or -1 if unknown.
 
211
     */
 
212
    public long getCompressedSize()
 
213
    {
 
214
        return csize;
 
215
    }
 
216
 
 
217
    /**
 
218
     * Sets the crc of the uncompressed data.
 
219
     * @exception IllegalArgumentException if crc is not in 0..0xffffffffL
 
220
     */
 
221
    public void setCrc(long crc)
 
222
    {
 
223
        if ((crc & 0xffffffff00000000L) != 0)
 
224
            throw new IllegalArgumentException();
 
225
        this.crc = crc;
 
226
    }
 
227
 
 
228
    /**
 
229
     * Gets the crc of the uncompressed data.
 
230
     * @return the crc or -1 if unknown.
 
231
     */
 
232
    public long getCrc()
 
233
    {
 
234
        return crc;
 
235
    }
 
236
 
 
237
    /**
 
238
     * Sets the compression method.  Only DEFLATED and STORED are
 
239
     * supported.
 
240
     * @exception IllegalArgumentException if method is not supported.
 
241
     * @see ZipOutputStream#DEFLATED
 
242
     * @see ZipOutputStream#STORED 
 
243
     */
 
244
    public void setMethod(int method)
 
245
    {
 
246
        if (method != ZipOutputStream.STORED
 
247
            && method != ZipOutputStream.DEFLATED)
 
248
            throw new IllegalArgumentException();
 
249
        this.method = method;
 
250
    }
 
251
 
 
252
    /**
 
253
     * Gets the compression method.  
 
254
     * @return the compression method or -1 if unknown.
 
255
     */
 
256
    public int getMethod()
 
257
    {
 
258
        return method;
 
259
    }
 
260
 
 
261
    /**
 
262
     * Sets the extra data.
 
263
     * @exception IllegalArgumentException if extra is longer than 0xffff bytes.
 
264
     */
 
265
    public void setExtra(byte[] extra)
 
266
    {
 
267
        if (extra == null)
 
268
        {
 
269
            this.extra = null;
 
270
            return;
 
271
        }
 
272
        if (extra.length > 0xffff)
 
273
            throw new IllegalArgumentException();
 
274
        this.extra = extra;
 
275
    }
 
276
 
 
277
    /**
 
278
     * Gets the extra data.
 
279
     * @return the extra data or null if not set.
 
280
     */
 
281
    public byte[] getExtra()
 
282
    {
 
283
        return extra;
 
284
    }
 
285
 
 
286
    /**
 
287
     * Sets the entry comment.
 
288
     */
 
289
    public void setComment(String comment)
 
290
    {
 
291
        this.comment = comment;
 
292
    }
 
293
 
 
294
    /**
 
295
     * Gets the comment.
 
296
     * @return the comment or null if not set.
 
297
     */
 
298
    public String getComment()
 
299
    {
 
300
        return comment;
 
301
    }
 
302
 
 
303
    /**
 
304
     * Gets true, if the entry is a directory.  This is solely
 
305
     * determined by the name, a trailing slash '/' marks a directory.  
 
306
     */
 
307
    public boolean isDirectory()
 
308
    {
 
309
        int nlen = name.length();
 
310
        return nlen > 0 && name.charAt(nlen - 1) == '/';
 
311
    }
 
312
 
 
313
    /**
 
314
     * Gets the string representation of this ZipEntry.  This is just
 
315
     * the name as returned by getName().
 
316
     */
 
317
    public String toString()
 
318
    {
 
319
        return getName();
 
320
    }
 
321
 
 
322
    /**
 
323
     * Gets the hashCode of this ZipEntry.  This is just the hashCode
 
324
     * of the name.  Note that the equals method isn't changed, though.
 
325
     */
 
326
    public int hashCode()
 
327
    {
 
328
        return name.hashCode();
 
329
    }
 
330
}