author | redestad |
Sat, 28 Feb 2015 13:17:13 +0100 | |
changeset 29226 | b675016fabfd |
parent 29095 | cb98c9bc4e6d |
child 29815 | a50c9d80a80f |
permissions | -rw-r--r-- |
2 | 1 |
/* |
29226 | 2 |
* Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.util.zip; |
|
27 |
||
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
28 |
import static java.util.zip.ZipUtils.*; |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
29 |
import java.nio.file.attribute.FileTime; |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
30 |
import java.util.Objects; |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
31 |
import java.util.concurrent.TimeUnit; |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
32 |
|
19843
71c34227ccb1
8024338: Constant fields introduced by JDK-4759491 fix in b94 are exposed as public fields in public API
sherman
parents:
19398
diff
changeset
|
33 |
import static java.util.zip.ZipConstants64.*; |
71c34227ccb1
8024338: Constant fields introduced by JDK-4759491 fix in b94 are exposed as public fields in public API
sherman
parents:
19398
diff
changeset
|
34 |
|
2 | 35 |
/** |
36 |
* This class is used to represent a ZIP file entry. |
|
37 |
* |
|
38 |
* @author David Connelly |
|
39 |
*/ |
|
40 |
public |
|
41 |
class ZipEntry implements ZipConstants, Cloneable { |
|
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
42 |
|
2 | 43 |
String name; // entry name |
29226 | 44 |
long xdostime = -1; // last modification time (in extended DOS time, |
45 |
// where milliseconds lost in conversion might |
|
46 |
// be encoded into the upper half) |
|
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
47 |
FileTime mtime; // last modification time, from extra field data |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
48 |
FileTime atime; // last access time, from extra field data |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
49 |
FileTime ctime; // creation time, from extra field data |
2 | 50 |
long crc = -1; // crc-32 of entry data |
51 |
long size = -1; // uncompressed size of entry data |
|
52 |
long csize = -1; // compressed size of entry data |
|
53 |
int method = -1; // compression method |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
54 |
int flag = 0; // general purpose flag |
2 | 55 |
byte[] extra; // optional extra field data for entry |
56 |
String comment; // optional comment string for entry |
|
57 |
||
58 |
/** |
|
59 |
* Compression method for uncompressed entries. |
|
60 |
*/ |
|
61 |
public static final int STORED = 0; |
|
62 |
||
63 |
/** |
|
64 |
* Compression method for compressed (deflated) entries. |
|
65 |
*/ |
|
66 |
public static final int DEFLATED = 8; |
|
67 |
||
68 |
/** |
|
29226 | 69 |
* DOS time constant for representing timestamps before 1980. |
70 |
*/ |
|
71 |
static final long DOSTIME_BEFORE_1980 = (1 << 21) | (1 << 16); |
|
72 |
||
73 |
/** |
|
74 |
* Approximately 128 years, in milliseconds (ignoring leap years etc). |
|
75 |
* |
|
76 |
* This establish an approximate high-bound value for DOS times in |
|
77 |
* milliseconds since epoch, used to enable an efficient but |
|
78 |
* sufficient bounds check to avoid generating extended last modified |
|
79 |
* time entries. |
|
80 |
* |
|
81 |
* Calculating the exact number is locale dependent, would require loading |
|
82 |
* TimeZone data eagerly, and would make little practical sense. Since DOS |
|
83 |
* times theoretically go to 2107 - with compatibility not guaranteed |
|
84 |
* after 2099 - setting this to a time that is before but near 2099 |
|
85 |
* should be sufficient. |
|
86 |
*/ |
|
87 |
private static final long UPPER_DOSTIME_BOUND = |
|
88 |
128L * 365 * 24 * 60 * 60 * 1000; |
|
89 |
||
90 |
/** |
|
2 | 91 |
* Creates a new zip entry with the specified name. |
92 |
* |
|
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
93 |
* @param name |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
94 |
* The entry name |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
95 |
* |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
96 |
* @throws NullPointerException if the entry name is null |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
97 |
* @throws IllegalArgumentException if the entry name is longer than |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
98 |
* 0xFFFF bytes |
2 | 99 |
*/ |
100 |
public ZipEntry(String name) { |
|
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
101 |
Objects.requireNonNull(name, "name"); |
2 | 102 |
if (name.length() > 0xFFFF) { |
103 |
throw new IllegalArgumentException("entry name too long"); |
|
104 |
} |
|
105 |
this.name = name; |
|
106 |
} |
|
107 |
||
108 |
/** |
|
109 |
* Creates a new zip entry with fields taken from the specified |
|
110 |
* zip entry. |
|
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
111 |
* |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
112 |
* @param e |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
113 |
* A zip Entry object |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
114 |
* |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
115 |
* @throws NullPointerException if the entry object is null |
2 | 116 |
*/ |
117 |
public ZipEntry(ZipEntry e) { |
|
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
118 |
Objects.requireNonNull(e, "entry"); |
2 | 119 |
name = e.name; |
29226 | 120 |
xdostime = e.xdostime; |
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
11274
diff
changeset
|
121 |
mtime = e.mtime; |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
122 |
atime = e.atime; |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
123 |
ctime = e.ctime; |
2 | 124 |
crc = e.crc; |
125 |
size = e.size; |
|
126 |
csize = e.csize; |
|
127 |
method = e.method; |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
128 |
flag = e.flag; |
2 | 129 |
extra = e.extra; |
130 |
comment = e.comment; |
|
131 |
} |
|
132 |
||
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
11274
diff
changeset
|
133 |
/** |
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
134 |
* Creates a new un-initialized zip entry |
2 | 135 |
*/ |
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
136 |
ZipEntry() {} |
2 | 137 |
|
138 |
/** |
|
139 |
* Returns the name of the entry. |
|
140 |
* @return the name of the entry |
|
141 |
*/ |
|
142 |
public String getName() { |
|
143 |
return name; |
|
144 |
} |
|
145 |
||
146 |
/** |
|
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
11274
diff
changeset
|
147 |
* Sets the last modification time of the entry. |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
11274
diff
changeset
|
148 |
* |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
149 |
* <p> If the entry is output to a ZIP file or ZIP file formatted |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
150 |
* output stream the last modification time set by this method will |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
151 |
* be stored into the {@code date and time fields} of the zip file |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
152 |
* entry and encoded in standard {@code MS-DOS date and time format}. |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
153 |
* The {@link java.util.TimeZone#getDefault() default TimeZone} is |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
154 |
* used to convert the epoch time to the MS-DOS data and time. |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
155 |
* |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
156 |
* @param time |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
157 |
* The last modification time of the entry in milliseconds |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
158 |
* since the epoch |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
159 |
* |
2 | 160 |
* @see #getTime() |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
161 |
* @see #getLastModifiedTime() |
2 | 162 |
*/ |
163 |
public void setTime(long time) { |
|
29226 | 164 |
this.xdostime = javaToExtendedDosTime(time); |
165 |
// Avoid setting the mtime field if time is in the valid |
|
166 |
// range for a DOS time |
|
167 |
if (xdostime != DOSTIME_BEFORE_1980 && time <= UPPER_DOSTIME_BOUND) { |
|
168 |
this.mtime = null; |
|
169 |
} else { |
|
170 |
this.mtime = FileTime.from(time, TimeUnit.MILLISECONDS); |
|
171 |
} |
|
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
172 |
} |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
173 |
|
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
174 |
/** |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
175 |
* Returns the last modification time of the entry. |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
176 |
* |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
177 |
* <p> If the entry is read from a ZIP file or ZIP file formatted |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
178 |
* input stream, this is the last modification time from the {@code |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
179 |
* date and time fields} of the zip file entry. The |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
180 |
* {@link java.util.TimeZone#getDefault() default TimeZone} is used |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
181 |
* to convert the standard MS-DOS formatted date and time to the |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
182 |
* epoch time. |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
183 |
* |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
184 |
* @return The last modification time of the entry in milliseconds |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
185 |
* since the epoch, or -1 if not specified |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
186 |
* |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
187 |
* @see #setTime(long) |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
188 |
* @see #setLastModifiedTime(FileTime) |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
189 |
*/ |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
190 |
public long getTime() { |
29226 | 191 |
if (mtime != null) { |
192 |
return mtime.toMillis(); |
|
193 |
} |
|
194 |
return (xdostime != -1) ? extendedDosToJavaTime(xdostime) : -1; |
|
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
195 |
} |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
196 |
|
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
197 |
/** |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
198 |
* Sets the last modification time of the entry. |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
199 |
* |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
200 |
* <p> When output to a ZIP file or ZIP file formatted output stream |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
201 |
* the last modification time set by this method will be stored into |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
202 |
* zip file entry's {@code date and time fields} in {@code standard |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
203 |
* MS-DOS date and time format}), and the extended timestamp fields |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
204 |
* in {@code optional extra data} in UTC time. |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
205 |
* |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
206 |
* @param time |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
207 |
* The last modification time of the entry |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
208 |
* @return This zip entry |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
209 |
* |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
210 |
* @throws NullPointerException if the {@code time} is null |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
211 |
* |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
212 |
* @see #getLastModifiedTime() |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
213 |
* @since 1.8 |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
214 |
*/ |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
215 |
public ZipEntry setLastModifiedTime(FileTime time) { |
29095
cb98c9bc4e6d
8068790: ZipEntry/JarEntry.setCreation/LastAccessTime(null) don't throw NPE as specified
redestad
parents:
25859
diff
changeset
|
216 |
this.mtime = Objects.requireNonNull(time, "lastModifiedTime"); |
29226 | 217 |
this.xdostime = javaToExtendedDosTime(time.to(TimeUnit.MILLISECONDS)); |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
218 |
return this; |
2 | 219 |
} |
220 |
||
221 |
/** |
|
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
11274
diff
changeset
|
222 |
* Returns the last modification time of the entry. |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
223 |
* |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
224 |
* <p> If the entry is read from a ZIP file or ZIP file formatted |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
225 |
* input stream, this is the last modification time from the zip |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
226 |
* file entry's {@code optional extra data} if the extended timestamp |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
227 |
* fields are present. Otherwise the last modification time is read |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
228 |
* from the entry's {@code date and time fields}, the {@link |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
229 |
* java.util.TimeZone#getDefault() default TimeZone} is used to convert |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
230 |
* the standard MS-DOS formatted date and time to the epoch time. |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
231 |
* |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
232 |
* @return The last modification time of the entry, null if not specified |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
233 |
* |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
234 |
* @see #setLastModifiedTime(FileTime) |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
235 |
* @since 1.8 |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
236 |
*/ |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
237 |
public FileTime getLastModifiedTime() { |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
238 |
if (mtime != null) |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
239 |
return mtime; |
29226 | 240 |
if (xdostime == -1) |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
241 |
return null; |
29226 | 242 |
return FileTime.from(getTime(), TimeUnit.MILLISECONDS); |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
243 |
} |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
244 |
|
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
245 |
/** |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
246 |
* Sets the last access time of the entry. |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
247 |
* |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
248 |
* <p> If set, the last access time will be stored into the extended |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
249 |
* timestamp fields of entry's {@code optional extra data}, when output |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
250 |
* to a ZIP file or ZIP file formatted stream. |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
251 |
* |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
252 |
* @param time |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
253 |
* The last access time of the entry |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
254 |
* @return This zip entry |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
255 |
* |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
256 |
* @throws NullPointerException if the {@code time} is null |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
257 |
* |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
258 |
* @see #getLastAccessTime() |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
259 |
* @since 1.8 |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
260 |
*/ |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
261 |
public ZipEntry setLastAccessTime(FileTime time) { |
29095
cb98c9bc4e6d
8068790: ZipEntry/JarEntry.setCreation/LastAccessTime(null) don't throw NPE as specified
redestad
parents:
25859
diff
changeset
|
262 |
this.atime = Objects.requireNonNull(time, "lastAccessTime"); |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
263 |
return this; |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
264 |
} |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
265 |
|
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
266 |
/** |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
267 |
* Returns the last access time of the entry. |
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
11274
diff
changeset
|
268 |
* |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
269 |
* <p> The last access time is from the extended timestamp fields |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
270 |
* of entry's {@code optional extra data} when read from a ZIP file |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
271 |
* or ZIP file formatted stream. |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
272 |
* |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
273 |
* @return The last access time of the entry, null if not specified |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
274 |
|
19398 | 275 |
* @see #setLastAccessTime(FileTime) |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
276 |
* @since 1.8 |
2 | 277 |
*/ |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
278 |
public FileTime getLastAccessTime() { |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
279 |
return atime; |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
280 |
} |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
281 |
|
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
282 |
/** |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
283 |
* Sets the creation time of the entry. |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
284 |
* |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
285 |
* <p> If set, the creation time will be stored into the extended |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
286 |
* timestamp fields of entry's {@code optional extra data}, when |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
287 |
* output to a ZIP file or ZIP file formatted stream. |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
288 |
* |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
289 |
* @param time |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
290 |
* The creation time of the entry |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
291 |
* @return This zip entry |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
292 |
* |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
293 |
* @throws NullPointerException if the {@code time} is null |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
294 |
* |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
295 |
* @see #getCreationTime() |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
296 |
* @since 1.8 |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
297 |
*/ |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
298 |
public ZipEntry setCreationTime(FileTime time) { |
29095
cb98c9bc4e6d
8068790: ZipEntry/JarEntry.setCreation/LastAccessTime(null) don't throw NPE as specified
redestad
parents:
25859
diff
changeset
|
299 |
this.ctime = Objects.requireNonNull(time, "creationTime"); |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
300 |
return this; |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
301 |
} |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
302 |
|
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
303 |
/** |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
304 |
* Returns the creation time of the entry. |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
305 |
* |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
306 |
* <p> The creation time is from the extended timestamp fields of |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
307 |
* entry's {@code optional extra data} when read from a ZIP file |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
308 |
* or ZIP file formatted stream. |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
309 |
* |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
310 |
* @return the creation time of the entry, null if not specified |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
311 |
* @see #setCreationTime(FileTime) |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
312 |
* @since 1.8 |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
313 |
*/ |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
314 |
public FileTime getCreationTime() { |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
315 |
return ctime; |
2 | 316 |
} |
317 |
||
318 |
/** |
|
319 |
* Sets the uncompressed size of the entry data. |
|
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
320 |
* |
2 | 321 |
* @param size the uncompressed size in bytes |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
322 |
* |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
323 |
* @throws IllegalArgumentException if the specified size is less |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
324 |
* than 0, is greater than 0xFFFFFFFF when |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
325 |
* <a href="package-summary.html#zip64">ZIP64 format</a> is not supported, |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
326 |
* or is less than 0 when ZIP64 is supported |
2 | 327 |
* @see #getSize() |
328 |
*/ |
|
329 |
public void setSize(long size) { |
|
2438 | 330 |
if (size < 0) { |
2 | 331 |
throw new IllegalArgumentException("invalid entry size"); |
332 |
} |
|
333 |
this.size = size; |
|
334 |
} |
|
335 |
||
336 |
/** |
|
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
337 |
* Returns the uncompressed size of the entry data. |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
338 |
* |
2 | 339 |
* @return the uncompressed size of the entry data, or -1 if not known |
340 |
* @see #setSize(long) |
|
341 |
*/ |
|
342 |
public long getSize() { |
|
343 |
return size; |
|
344 |
} |
|
345 |
||
346 |
/** |
|
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
347 |
* Returns the size of the compressed entry data. |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
348 |
* |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
349 |
* <p> In the case of a stored entry, the compressed size will be the same |
2 | 350 |
* as the uncompressed size of the entry. |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
351 |
* |
2 | 352 |
* @return the size of the compressed entry data, or -1 if not known |
353 |
* @see #setCompressedSize(long) |
|
354 |
*/ |
|
355 |
public long getCompressedSize() { |
|
356 |
return csize; |
|
357 |
} |
|
358 |
||
359 |
/** |
|
360 |
* Sets the size of the compressed entry data. |
|
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
361 |
* |
2 | 362 |
* @param csize the compressed size to set to |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
363 |
* |
2 | 364 |
* @see #getCompressedSize() |
365 |
*/ |
|
366 |
public void setCompressedSize(long csize) { |
|
367 |
this.csize = csize; |
|
368 |
} |
|
369 |
||
370 |
/** |
|
371 |
* Sets the CRC-32 checksum of the uncompressed entry data. |
|
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
372 |
* |
2 | 373 |
* @param crc the CRC-32 value |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
374 |
* |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
375 |
* @throws IllegalArgumentException if the specified CRC-32 value is |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
376 |
* less than 0 or greater than 0xFFFFFFFF |
2 | 377 |
* @see #getCrc() |
378 |
*/ |
|
379 |
public void setCrc(long crc) { |
|
380 |
if (crc < 0 || crc > 0xFFFFFFFFL) { |
|
381 |
throw new IllegalArgumentException("invalid entry crc-32"); |
|
382 |
} |
|
383 |
this.crc = crc; |
|
384 |
} |
|
385 |
||
386 |
/** |
|
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
387 |
* Returns the CRC-32 checksum of the uncompressed entry data. |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
388 |
* |
2 | 389 |
* @return the CRC-32 checksum of the uncompressed entry data, or -1 if |
390 |
* not known |
|
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
391 |
* |
2 | 392 |
* @see #setCrc(long) |
393 |
*/ |
|
394 |
public long getCrc() { |
|
395 |
return crc; |
|
396 |
} |
|
397 |
||
398 |
/** |
|
399 |
* Sets the compression method for the entry. |
|
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
400 |
* |
2 | 401 |
* @param method the compression method, either STORED or DEFLATED |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
402 |
* |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
403 |
* @throws IllegalArgumentException if the specified compression |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
404 |
* method is invalid |
2 | 405 |
* @see #getMethod() |
406 |
*/ |
|
407 |
public void setMethod(int method) { |
|
408 |
if (method != STORED && method != DEFLATED) { |
|
409 |
throw new IllegalArgumentException("invalid compression method"); |
|
410 |
} |
|
411 |
this.method = method; |
|
412 |
} |
|
413 |
||
414 |
/** |
|
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
415 |
* Returns the compression method of the entry. |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
416 |
* |
2 | 417 |
* @return the compression method of the entry, or -1 if not specified |
418 |
* @see #setMethod(int) |
|
419 |
*/ |
|
420 |
public int getMethod() { |
|
421 |
return method; |
|
422 |
} |
|
423 |
||
424 |
/** |
|
425 |
* Sets the optional extra field data for the entry. |
|
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
426 |
* |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
427 |
* <p> Invoking this method may change this entry's last modification |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
428 |
* time, last access time and creation time, if the {@code extra} field |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
429 |
* data includes the extensible timestamp fields, such as {@code NTFS tag |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
430 |
* 0x0001} or {@code Info-ZIP Extended Timestamp}, as specified in |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
431 |
* <a href="http://www.info-zip.org/doc/appnote-19970311-iz.zip">Info-ZIP |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
432 |
* Application Note 970311</a>. |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
433 |
* |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
434 |
* @param extra |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
435 |
* The extra field data bytes |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
436 |
* |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
437 |
* @throws IllegalArgumentException if the length of the specified |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
438 |
* extra field data is greater than 0xFFFF bytes |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
439 |
* |
2 | 440 |
* @see #getExtra() |
441 |
*/ |
|
442 |
public void setExtra(byte[] extra) { |
|
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
443 |
setExtra0(extra, false); |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
444 |
} |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
445 |
|
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
446 |
/** |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
447 |
* Sets the optional extra field data for the entry. |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
448 |
* |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
449 |
* @param extra |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
450 |
* the extra field data bytes |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
451 |
* @param doZIP64 |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
452 |
* if true, set size and csize from ZIP64 fields if present |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
453 |
*/ |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
454 |
void setExtra0(byte[] extra, boolean doZIP64) { |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
455 |
if (extra != null) { |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
456 |
if (extra.length > 0xFFFF) { |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
457 |
throw new IllegalArgumentException("invalid extra field length"); |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
458 |
} |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
459 |
// extra fields are in "HeaderID(2)DataSize(2)Data... format |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
460 |
int off = 0; |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
461 |
int len = extra.length; |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
462 |
while (off + 4 < len) { |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
463 |
int tag = get16(extra, off); |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
464 |
int sz = get16(extra, off + 2); |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
465 |
off += 4; |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
466 |
if (off + sz > len) // invalid data |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
467 |
break; |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
468 |
switch (tag) { |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
469 |
case EXTID_ZIP64: |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
470 |
if (doZIP64) { |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
471 |
// LOC extra zip64 entry MUST include BOTH original |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
472 |
// and compressed file size fields. |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
473 |
// If invalid zip64 extra fields, simply skip. Even |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
474 |
// it's rare, it's possible the entry size happens to |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
475 |
// be the magic value and it "accidently" has some |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
476 |
// bytes in extra match the id. |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
477 |
if (sz >= 16) { |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
478 |
size = get64(extra, off); |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
479 |
csize = get64(extra, off + 8); |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
480 |
} |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
481 |
} |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
482 |
break; |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
483 |
case EXTID_NTFS: |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
484 |
int pos = off + 4; // reserved 4 bytes |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
485 |
if (get16(extra, pos) != 0x0001 || get16(extra, pos + 2) != 24) |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
486 |
break; |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
487 |
mtime = winTimeToFileTime(get64(extra, pos + 4)); |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
488 |
atime = winTimeToFileTime(get64(extra, pos + 12)); |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
489 |
ctime = winTimeToFileTime(get64(extra, pos + 20)); |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
490 |
break; |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
491 |
case EXTID_EXTT: |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
492 |
int flag = Byte.toUnsignedInt(extra[off]); |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
493 |
int sz0 = 1; |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
494 |
// The CEN-header extra field contains the modification |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
495 |
// time only, or no timestamp at all. 'sz' is used to |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
496 |
// flag its presence or absence. But if mtime is present |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
497 |
// in LOC it must be present in CEN as well. |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
498 |
if ((flag & 0x1) != 0 && (sz0 + 4) <= sz) { |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
499 |
mtime = unixTimeToFileTime(get32(extra, off + sz0)); |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
500 |
sz0 += 4; |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
501 |
} |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
502 |
if ((flag & 0x2) != 0 && (sz0 + 4) <= sz) { |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
503 |
atime = unixTimeToFileTime(get32(extra, off + sz0)); |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
504 |
sz0 += 4; |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
505 |
} |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
506 |
if ((flag & 0x4) != 0 && (sz0 + 4) <= sz) { |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
507 |
ctime = unixTimeToFileTime(get32(extra, off + sz0)); |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
508 |
sz0 += 4; |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
509 |
} |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
510 |
break; |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
511 |
default: |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
512 |
} |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
513 |
off += sz; |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
514 |
} |
2 | 515 |
} |
516 |
this.extra = extra; |
|
517 |
} |
|
518 |
||
519 |
/** |
|
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
520 |
* Returns the extra field data for the entry. |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
521 |
* |
2 | 522 |
* @return the extra field data for the entry, or null if none |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
523 |
* |
2 | 524 |
* @see #setExtra(byte[]) |
525 |
*/ |
|
526 |
public byte[] getExtra() { |
|
527 |
return extra; |
|
528 |
} |
|
529 |
||
530 |
/** |
|
531 |
* Sets the optional comment string for the entry. |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
532 |
* |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
533 |
* <p>ZIP entry comments have maximum length of 0xffff. If the length of the |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
534 |
* specified comment string is greater than 0xFFFF bytes after encoding, only |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
535 |
* the first 0xFFFF bytes are output to the ZIP file entry. |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
536 |
* |
2 | 537 |
* @param comment the comment string |
3844
74c6b6e2db6c
6881337: ZipEntry.setComment() was accidentally changed back to old spec/impl in jdk7-b64
sherman
parents:
3111
diff
changeset
|
538 |
* |
2 | 539 |
* @see #getComment() |
540 |
*/ |
|
541 |
public void setComment(String comment) { |
|
542 |
this.comment = comment; |
|
543 |
} |
|
544 |
||
545 |
/** |
|
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
546 |
* Returns the comment string for the entry. |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
547 |
* |
2 | 548 |
* @return the comment string for the entry, or null if none |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
549 |
* |
2 | 550 |
* @see #setComment(String) |
551 |
*/ |
|
552 |
public String getComment() { |
|
553 |
return comment; |
|
554 |
} |
|
555 |
||
556 |
/** |
|
557 |
* Returns true if this is a directory entry. A directory entry is |
|
558 |
* defined to be one whose name ends with a '/'. |
|
559 |
* @return true if this is a directory entry |
|
560 |
*/ |
|
561 |
public boolean isDirectory() { |
|
562 |
return name.endsWith("/"); |
|
563 |
} |
|
564 |
||
565 |
/** |
|
566 |
* Returns a string representation of the ZIP entry. |
|
567 |
*/ |
|
568 |
public String toString() { |
|
569 |
return getName(); |
|
570 |
} |
|
571 |
||
572 |
/** |
|
573 |
* Returns the hash code value for this entry. |
|
574 |
*/ |
|
575 |
public int hashCode() { |
|
576 |
return name.hashCode(); |
|
577 |
} |
|
578 |
||
579 |
/** |
|
580 |
* Returns a copy of this entry. |
|
581 |
*/ |
|
582 |
public Object clone() { |
|
583 |
try { |
|
584 |
ZipEntry e = (ZipEntry)super.clone(); |
|
585 |
e.extra = (extra == null) ? null : extra.clone(); |
|
586 |
return e; |
|
587 |
} catch (CloneNotSupportedException e) { |
|
588 |
// This should never happen, since we are Cloneable |
|
10419
12c063b39232
7084245: Update usages of InternalError to use exception chaining
sherman
parents:
9035
diff
changeset
|
589 |
throw new InternalError(e); |
2 | 590 |
} |
591 |
} |
|
592 |
} |