2
Copyright (C) 2001, 2002, 2004, 2005, 2011 Free Software Foundation, Inc.
4
This file is part of GNU Classpath.
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)
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.
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
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
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. */
39
package java.util.zip;
41
import java.util.Date;
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.
49
* @author Jochen Hoenicke
51
public class ZipEntry implements ZipConstants, Cloneable
63
long offset; /* used by ZipFile */
66
* Compression method. This method doesn't compress at all.
68
public static final int STORED = 0;
70
* Compression method. This method uses the Deflater.
72
public static final int DEFLATED = 8;
75
* Creates a zip entry with the given name.
76
* @param name the name. May include directory components separated
79
* @exception NullPointerException when name is null.
80
* @exception IllegalArgumentException when name is bigger then 65535 chars.
82
public ZipEntry(String name)
84
int length = name.length();
86
throw new IllegalArgumentException("name length is " + length);
91
* Creates a copy of the given zip entry.
92
* @param e the entry to copy.
94
public ZipEntry(ZipEntry e)
112
* Creates a copy of this zip entry.
117
public Object clone()
121
// The JCL says that the `extra' field is also copied.
122
ZipEntry clone = (ZipEntry)super.clone();
124
clone.extra = (byte[])extra.clone();
127
catch (CloneNotSupportedException ex)
129
throw new InternalError();
134
* Returns the entry name. The path components in the entry are
135
* always separated by slashes ('/').
137
public String getName()
143
* Sets the time of last modification of the entry.
144
* @time the time of last modification of the entry.
146
public void setTime(long time)
148
Date d = new Date(time);
149
if (d.getYear() < 80)
151
d = new Date(80, 0, 1);
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);
162
* Gets the time of last modification of the entry.
163
* @return the time of last modification of the entry, or -1 if unknown.
165
public long getTime()
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));
181
* Sets the size of the uncompressed data.
182
* @exception IllegalArgumentException if size is negative.
184
public void setSize(long size)
187
throw new IllegalArgumentException();
192
* Gets the size of the uncompressed data.
193
* @return the size or -1 if unknown.
195
public long getSize()
201
* Sets the size of the compressed data.
203
public void setCompressedSize(long csize)
209
* Gets the size of the compressed data.
210
* @return the size or -1 if unknown.
212
public long getCompressedSize()
218
* Sets the crc of the uncompressed data.
219
* @exception IllegalArgumentException if crc is not in 0..0xffffffffL
221
public void setCrc(long crc)
223
if ((crc & 0xffffffff00000000L) != 0)
224
throw new IllegalArgumentException();
229
* Gets the crc of the uncompressed data.
230
* @return the crc or -1 if unknown.
238
* Sets the compression method. Only DEFLATED and STORED are
240
* @exception IllegalArgumentException if method is not supported.
241
* @see ZipOutputStream#DEFLATED
242
* @see ZipOutputStream#STORED
244
public void setMethod(int method)
246
if (method != ZipOutputStream.STORED
247
&& method != ZipOutputStream.DEFLATED)
248
throw new IllegalArgumentException();
249
this.method = method;
253
* Gets the compression method.
254
* @return the compression method or -1 if unknown.
256
public int getMethod()
262
* Sets the extra data.
263
* @exception IllegalArgumentException if extra is longer than 0xffff bytes.
265
public void setExtra(byte[] extra)
272
if (extra.length > 0xffff)
273
throw new IllegalArgumentException();
278
* Gets the extra data.
279
* @return the extra data or null if not set.
281
public byte[] getExtra()
287
* Sets the entry comment.
289
public void setComment(String comment)
291
this.comment = comment;
296
* @return the comment or null if not set.
298
public String getComment()
304
* Gets true, if the entry is a directory. This is solely
305
* determined by the name, a trailing slash '/' marks a directory.
307
public boolean isDirectory()
309
int nlen = name.length();
310
return nlen > 0 && name.charAt(nlen - 1) == '/';
314
* Gets the string representation of this ZipEntry. This is just
315
* the name as returned by getName().
317
public String toString()
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.
326
public int hashCode()
328
return name.hashCode();