author | jboes |
Fri, 20 Sep 2019 11:07:52 +0100 | |
changeset 58242 | 94bb65cb37d3 |
parent 50955 | 1acfd2f56d72 |
child 59201 | b24f4caa1411 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
50955
diff
changeset
|
2 |
* Copyright (c) 1996, 2019, 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 |
||
28 |
import java.io.OutputStream; |
|
29 |
import java.io.IOException; |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
30 |
import java.nio.charset.Charset; |
9676
5663e62f8d7e
7041612: Rename StandardCharset to StandardCharsets
mduigou
parents:
9526
diff
changeset
|
31 |
import java.nio.charset.StandardCharsets; |
2 | 32 |
import java.util.Vector; |
33 |
import java.util.HashSet; |
|
2438
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
34 |
import static java.util.zip.ZipConstants64.*; |
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16713
diff
changeset
|
35 |
import static java.util.zip.ZipUtils.*; |
37593
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
29226
diff
changeset
|
36 |
import sun.security.action.GetPropertyAction; |
2 | 37 |
|
38 |
/** |
|
39 |
* This class implements an output stream filter for writing files in the |
|
40 |
* ZIP file format. Includes support for both compressed and uncompressed |
|
41 |
* entries. |
|
42 |
* |
|
43 |
* @author David Connelly |
|
45434
4582657c7260
8181082: class-level since tag issues in java.base & java.datatransfer module
mli
parents:
39772
diff
changeset
|
44 |
* @since 1.1 |
2 | 45 |
*/ |
46 |
public |
|
47 |
class ZipOutputStream extends DeflaterOutputStream implements ZipConstants { |
|
48 |
||
16713
7824dded9821
8007905: To add a system property to create zip file without using ZIP64 end table when entry count > 64k
martin
parents:
14342
diff
changeset
|
49 |
/** |
7824dded9821
8007905: To add a system property to create zip file without using ZIP64 end table when entry count > 64k
martin
parents:
14342
diff
changeset
|
50 |
* Whether to use ZIP64 for zip files with more than 64k entries. |
7824dded9821
8007905: To add a system property to create zip file without using ZIP64 end table when entry count > 64k
martin
parents:
14342
diff
changeset
|
51 |
* Until ZIP64 support in zip implementations is ubiquitous, this |
7824dded9821
8007905: To add a system property to create zip file without using ZIP64 end table when entry count > 64k
martin
parents:
14342
diff
changeset
|
52 |
* system property allows the creation of zip files which can be |
7824dded9821
8007905: To add a system property to create zip file without using ZIP64 end table when entry count > 64k
martin
parents:
14342
diff
changeset
|
53 |
* read by legacy zip implementations which tolerate "incorrect" |
7824dded9821
8007905: To add a system property to create zip file without using ZIP64 end table when entry count > 64k
martin
parents:
14342
diff
changeset
|
54 |
* total entry count fields, such as the ones in jdk6, and even |
7824dded9821
8007905: To add a system property to create zip file without using ZIP64 end table when entry count > 64k
martin
parents:
14342
diff
changeset
|
55 |
* some in jdk7. |
7824dded9821
8007905: To add a system property to create zip file without using ZIP64 end table when entry count > 64k
martin
parents:
14342
diff
changeset
|
56 |
*/ |
7824dded9821
8007905: To add a system property to create zip file without using ZIP64 end table when entry count > 64k
martin
parents:
14342
diff
changeset
|
57 |
private static final boolean inhibitZip64 = |
7824dded9821
8007905: To add a system property to create zip file without using ZIP64 end table when entry count > 64k
martin
parents:
14342
diff
changeset
|
58 |
Boolean.parseBoolean( |
37781
71ed5645f17c
8155775: Re-examine naming of privileged methods to access System properties
redestad
parents:
37593
diff
changeset
|
59 |
GetPropertyAction.privilegedGetProperty("jdk.util.zip.inhibitZip64")); |
16713
7824dded9821
8007905: To add a system property to create zip file without using ZIP64 end table when entry count > 64k
martin
parents:
14342
diff
changeset
|
60 |
|
2 | 61 |
private static class XEntry { |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
62 |
final ZipEntry entry; |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
63 |
final long offset; |
2 | 64 |
public XEntry(ZipEntry entry, long offset) { |
65 |
this.entry = entry; |
|
66 |
this.offset = offset; |
|
67 |
} |
|
68 |
} |
|
69 |
||
70 |
private XEntry current; |
|
7803
56bc97d69d93
6880112: Project Coin: Port JDK core library code to use diamond operator
smarks
parents:
5506
diff
changeset
|
71 |
private Vector<XEntry> xentries = new Vector<>(); |
56bc97d69d93
6880112: Project Coin: Port JDK core library code to use diamond operator
smarks
parents:
5506
diff
changeset
|
72 |
private HashSet<String> names = new HashSet<>(); |
2 | 73 |
private CRC32 crc = new CRC32(); |
74 |
private long written = 0; |
|
75 |
private long locoff = 0; |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
76 |
private byte[] comment; |
2 | 77 |
private int method = DEFLATED; |
78 |
private boolean finished; |
|
79 |
||
80 |
private boolean closed = false; |
|
81 |
||
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
82 |
private final ZipCoder zc; |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
83 |
|
2 | 84 |
private static int version(ZipEntry e) throws ZipException { |
85 |
switch (e.method) { |
|
86 |
case DEFLATED: return 20; |
|
87 |
case STORED: return 10; |
|
88 |
default: throw new ZipException("unsupported compression method"); |
|
89 |
} |
|
90 |
} |
|
91 |
||
92 |
/** |
|
93 |
* Checks to make sure that this stream has not been closed. |
|
94 |
*/ |
|
95 |
private void ensureOpen() throws IOException { |
|
96 |
if (closed) { |
|
97 |
throw new IOException("Stream closed"); |
|
98 |
} |
|
99 |
} |
|
50238
a9307f400f5a
8203328: Rename EFS in java.util.zip internals to something meaningful
martin
parents:
47216
diff
changeset
|
100 |
|
2 | 101 |
/** |
102 |
* Compression method for uncompressed (STORED) entries. |
|
103 |
*/ |
|
104 |
public static final int STORED = ZipEntry.STORED; |
|
105 |
||
106 |
/** |
|
107 |
* Compression method for compressed (DEFLATED) entries. |
|
108 |
*/ |
|
109 |
public static final int DEFLATED = ZipEntry.DEFLATED; |
|
110 |
||
111 |
/** |
|
112 |
* Creates a new ZIP output stream. |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
113 |
* |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
114 |
* <p>The UTF-8 {@link java.nio.charset.Charset charset} is used |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
115 |
* to encode the entry names and comments. |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
116 |
* |
2 | 117 |
* @param out the actual output stream |
118 |
*/ |
|
119 |
public ZipOutputStream(OutputStream out) { |
|
9676
5663e62f8d7e
7041612: Rename StandardCharset to StandardCharsets
mduigou
parents:
9526
diff
changeset
|
120 |
this(out, StandardCharsets.UTF_8); |
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
121 |
} |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
122 |
|
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
123 |
/** |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
124 |
* Creates a new ZIP output stream. |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
125 |
* |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
126 |
* @param out the actual output stream |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
127 |
* |
2704
a92617170304
6836489: Incorrect @link usage in java.util.zip API doc
sherman
parents:
2592
diff
changeset
|
128 |
* @param charset the {@linkplain java.nio.charset.Charset charset} |
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
129 |
* to be used to encode the entry names and comments |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
130 |
* |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
131 |
* @since 1.7 |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
132 |
*/ |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
133 |
public ZipOutputStream(OutputStream out, Charset charset) { |
2 | 134 |
super(out, new Deflater(Deflater.DEFAULT_COMPRESSION, true)); |
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
135 |
if (charset == null) |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
136 |
throw new NullPointerException("charset is null"); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
137 |
this.zc = ZipCoder.get(charset); |
2 | 138 |
usesDefaultDeflater = true; |
139 |
} |
|
140 |
||
141 |
/** |
|
142 |
* Sets the ZIP file comment. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
50955
diff
changeset
|
143 |
* @param comment the comment string |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
50955
diff
changeset
|
144 |
* @throws IllegalArgumentException if the length of the specified |
2 | 145 |
* ZIP file comment is greater than 0xFFFF bytes |
146 |
*/ |
|
147 |
public void setComment(String comment) { |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
148 |
if (comment != null) { |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
149 |
this.comment = zc.getBytes(comment); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
150 |
if (this.comment.length > 0xffff) |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
151 |
throw new IllegalArgumentException("ZIP file comment too long."); |
2 | 152 |
} |
153 |
} |
|
154 |
||
155 |
/** |
|
156 |
* Sets the default compression method for subsequent entries. This |
|
157 |
* default will be used whenever the compression method is not specified |
|
158 |
* for an individual ZIP file entry, and is initially set to DEFLATED. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
50955
diff
changeset
|
159 |
* @param method the default compression method |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
50955
diff
changeset
|
160 |
* @throws IllegalArgumentException if the specified compression method |
2 | 161 |
* is invalid |
162 |
*/ |
|
163 |
public void setMethod(int method) { |
|
164 |
if (method != DEFLATED && method != STORED) { |
|
165 |
throw new IllegalArgumentException("invalid compression method"); |
|
166 |
} |
|
167 |
this.method = method; |
|
168 |
} |
|
169 |
||
170 |
/** |
|
171 |
* Sets the compression level for subsequent entries which are DEFLATED. |
|
172 |
* The default setting is DEFAULT_COMPRESSION. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
50955
diff
changeset
|
173 |
* @param level the compression level (0-9) |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
50955
diff
changeset
|
174 |
* @throws IllegalArgumentException if the compression level is invalid |
2 | 175 |
*/ |
176 |
public void setLevel(int level) { |
|
177 |
def.setLevel(level); |
|
178 |
} |
|
179 |
||
180 |
/** |
|
181 |
* Begins writing a new ZIP file entry and positions the stream to the |
|
182 |
* start of the entry data. Closes the current entry if still active. |
|
183 |
* The default compression method will be used if no compression method |
|
184 |
* was specified for the entry, and the current time will be used if |
|
185 |
* the entry has no set modification time. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
50955
diff
changeset
|
186 |
* @param e the ZIP entry to be written |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
50955
diff
changeset
|
187 |
* @throws ZipException if a ZIP format error has occurred |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
50955
diff
changeset
|
188 |
* @throws IOException if an I/O error has occurred |
2 | 189 |
*/ |
190 |
public void putNextEntry(ZipEntry e) throws IOException { |
|
191 |
ensureOpen(); |
|
192 |
if (current != null) { |
|
193 |
closeEntry(); // close previous entry |
|
194 |
} |
|
29226 | 195 |
if (e.xdostime == -1) { |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
196 |
// by default, do NOT use extended timestamps in extra |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
197 |
// data, for now. |
2 | 198 |
e.setTime(System.currentTimeMillis()); |
199 |
} |
|
200 |
if (e.method == -1) { |
|
201 |
e.method = method; // use default method |
|
202 |
} |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
203 |
// store size, compressed size, and crc-32 in LOC header |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
204 |
e.flag = 0; |
2 | 205 |
switch (e.method) { |
206 |
case DEFLATED: |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
207 |
// store size, compressed size, and crc-32 in data descriptor |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
208 |
// immediately following the compressed entry data |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
209 |
if (e.size == -1 || e.csize == -1 || e.crc == -1) |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
210 |
e.flag = 8; |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
211 |
|
2 | 212 |
break; |
213 |
case STORED: |
|
214 |
// compressed size, uncompressed size, and crc-32 must all be |
|
215 |
// set for entries using STORED compression method |
|
216 |
if (e.size == -1) { |
|
217 |
e.size = e.csize; |
|
218 |
} else if (e.csize == -1) { |
|
219 |
e.csize = e.size; |
|
220 |
} else if (e.size != e.csize) { |
|
221 |
throw new ZipException( |
|
222 |
"STORED entry where compressed != uncompressed size"); |
|
223 |
} |
|
224 |
if (e.size == -1 || e.crc == -1) { |
|
225 |
throw new ZipException( |
|
226 |
"STORED entry missing size, compressed size, or crc-32"); |
|
227 |
} |
|
228 |
break; |
|
229 |
default: |
|
230 |
throw new ZipException("unsupported compression method"); |
|
231 |
} |
|
232 |
if (! names.add(e.name)) { |
|
233 |
throw new ZipException("duplicate entry: " + e.name); |
|
234 |
} |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
235 |
if (zc.isUTF8()) |
50238
a9307f400f5a
8203328: Rename EFS in java.util.zip internals to something meaningful
martin
parents:
47216
diff
changeset
|
236 |
e.flag |= USE_UTF8; |
2 | 237 |
current = new XEntry(e, written); |
238 |
xentries.add(current); |
|
239 |
writeLOC(current); |
|
240 |
} |
|
241 |
||
242 |
/** |
|
243 |
* Closes the current ZIP entry and positions the stream for writing |
|
244 |
* the next entry. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
50955
diff
changeset
|
245 |
* @throws ZipException if a ZIP format error has occurred |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
50955
diff
changeset
|
246 |
* @throws IOException if an I/O error has occurred |
2 | 247 |
*/ |
248 |
public void closeEntry() throws IOException { |
|
249 |
ensureOpen(); |
|
250 |
if (current != null) { |
|
251 |
ZipEntry e = current.entry; |
|
252 |
switch (e.method) { |
|
253 |
case DEFLATED: |
|
254 |
def.finish(); |
|
255 |
while (!def.finished()) { |
|
256 |
deflate(); |
|
257 |
} |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
258 |
if ((e.flag & 8) == 0) { |
2 | 259 |
// verify size, compressed size, and crc-32 settings |
260 |
if (e.size != def.getBytesRead()) { |
|
261 |
throw new ZipException( |
|
262 |
"invalid entry size (expected " + e.size + |
|
263 |
" but got " + def.getBytesRead() + " bytes)"); |
|
264 |
} |
|
265 |
if (e.csize != def.getBytesWritten()) { |
|
266 |
throw new ZipException( |
|
267 |
"invalid entry compressed size (expected " + |
|
268 |
e.csize + " but got " + def.getBytesWritten() + " bytes)"); |
|
269 |
} |
|
270 |
if (e.crc != crc.getValue()) { |
|
271 |
throw new ZipException( |
|
272 |
"invalid entry CRC-32 (expected 0x" + |
|
273 |
Long.toHexString(e.crc) + " but got 0x" + |
|
274 |
Long.toHexString(crc.getValue()) + ")"); |
|
275 |
} |
|
276 |
} else { |
|
277 |
e.size = def.getBytesRead(); |
|
278 |
e.csize = def.getBytesWritten(); |
|
279 |
e.crc = crc.getValue(); |
|
280 |
writeEXT(e); |
|
281 |
} |
|
282 |
def.reset(); |
|
283 |
written += e.csize; |
|
284 |
break; |
|
285 |
case STORED: |
|
286 |
// we already know that both e.size and e.csize are the same |
|
287 |
if (e.size != written - locoff) { |
|
288 |
throw new ZipException( |
|
289 |
"invalid entry size (expected " + e.size + |
|
290 |
" but got " + (written - locoff) + " bytes)"); |
|
291 |
} |
|
292 |
if (e.crc != crc.getValue()) { |
|
293 |
throw new ZipException( |
|
294 |
"invalid entry crc-32 (expected 0x" + |
|
295 |
Long.toHexString(e.crc) + " but got 0x" + |
|
296 |
Long.toHexString(crc.getValue()) + ")"); |
|
297 |
} |
|
298 |
break; |
|
299 |
default: |
|
300 |
throw new ZipException("invalid compression method"); |
|
301 |
} |
|
302 |
crc.reset(); |
|
303 |
current = null; |
|
304 |
} |
|
305 |
} |
|
306 |
||
307 |
/** |
|
308 |
* Writes an array of bytes to the current ZIP entry data. This method |
|
309 |
* will block until all the bytes are written. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
50955
diff
changeset
|
310 |
* @param b the data to be written |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
50955
diff
changeset
|
311 |
* @param off the start offset in the data |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
50955
diff
changeset
|
312 |
* @param len the number of bytes that are written |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
50955
diff
changeset
|
313 |
* @throws ZipException if a ZIP file error has occurred |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
50955
diff
changeset
|
314 |
* @throws IOException if an I/O error has occurred |
2 | 315 |
*/ |
316 |
public synchronized void write(byte[] b, int off, int len) |
|
317 |
throws IOException |
|
318 |
{ |
|
319 |
ensureOpen(); |
|
320 |
if (off < 0 || len < 0 || off > b.length - len) { |
|
321 |
throw new IndexOutOfBoundsException(); |
|
322 |
} else if (len == 0) { |
|
323 |
return; |
|
324 |
} |
|
325 |
||
326 |
if (current == null) { |
|
327 |
throw new ZipException("no current ZIP entry"); |
|
328 |
} |
|
329 |
ZipEntry entry = current.entry; |
|
330 |
switch (entry.method) { |
|
331 |
case DEFLATED: |
|
332 |
super.write(b, off, len); |
|
333 |
break; |
|
334 |
case STORED: |
|
335 |
written += len; |
|
336 |
if (written - locoff > entry.size) { |
|
337 |
throw new ZipException( |
|
338 |
"attempt to write past end of STORED entry"); |
|
339 |
} |
|
340 |
out.write(b, off, len); |
|
341 |
break; |
|
342 |
default: |
|
343 |
throw new ZipException("invalid compression method"); |
|
344 |
} |
|
345 |
crc.update(b, off, len); |
|
346 |
} |
|
347 |
||
348 |
/** |
|
349 |
* Finishes writing the contents of the ZIP output stream without closing |
|
350 |
* the underlying stream. Use this method when applying multiple filters |
|
351 |
* in succession to the same output stream. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
50955
diff
changeset
|
352 |
* @throws ZipException if a ZIP file error has occurred |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
50955
diff
changeset
|
353 |
* @throws IOException if an I/O exception has occurred |
2 | 354 |
*/ |
355 |
public void finish() throws IOException { |
|
356 |
ensureOpen(); |
|
357 |
if (finished) { |
|
358 |
return; |
|
359 |
} |
|
360 |
if (current != null) { |
|
361 |
closeEntry(); |
|
362 |
} |
|
363 |
// write central directory |
|
364 |
long off = written; |
|
365 |
for (XEntry xentry : xentries) |
|
366 |
writeCEN(xentry); |
|
367 |
writeEND(off, written - off); |
|
368 |
finished = true; |
|
369 |
} |
|
370 |
||
371 |
/** |
|
372 |
* Closes the ZIP output stream as well as the stream being filtered. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
50955
diff
changeset
|
373 |
* @throws ZipException if a ZIP file error has occurred |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
50955
diff
changeset
|
374 |
* @throws IOException if an I/O error has occurred |
2 | 375 |
*/ |
376 |
public void close() throws IOException { |
|
377 |
if (!closed) { |
|
378 |
super.close(); |
|
379 |
closed = true; |
|
380 |
} |
|
381 |
} |
|
382 |
||
383 |
/* |
|
384 |
* Writes local file (LOC) header for specified entry. |
|
385 |
*/ |
|
386 |
private void writeLOC(XEntry xentry) throws IOException { |
|
387 |
ZipEntry e = xentry.entry; |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
388 |
int flag = e.flag; |
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16713
diff
changeset
|
389 |
boolean hasZip64 = false; |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
390 |
int elen = getExtraLen(e.extra); |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
391 |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
392 |
writeInt(LOCSIG); // LOC header signature |
2 | 393 |
if ((flag & 8) == 8) { |
2438
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
394 |
writeShort(version(e)); // version needed to extract |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
395 |
writeShort(flag); // general purpose bit flag |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
396 |
writeShort(e.method); // compression method |
29226 | 397 |
writeInt(e.xdostime); // last modification time |
2 | 398 |
// store size, uncompressed size, and crc-32 in data descriptor |
399 |
// immediately following compressed entry data |
|
400 |
writeInt(0); |
|
401 |
writeInt(0); |
|
402 |
writeInt(0); |
|
403 |
} else { |
|
2438
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
404 |
if (e.csize >= ZIP64_MAGICVAL || e.size >= ZIP64_MAGICVAL) { |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
405 |
hasZip64 = true; |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
406 |
writeShort(45); // ver 4.5 for zip64 |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
407 |
} else { |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
408 |
writeShort(version(e)); // version needed to extract |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
409 |
} |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
410 |
writeShort(flag); // general purpose bit flag |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
411 |
writeShort(e.method); // compression method |
29226 | 412 |
writeInt(e.xdostime); // last modification time |
2438
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
413 |
writeInt(e.crc); // crc-32 |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
414 |
if (hasZip64) { |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
415 |
writeInt(ZIP64_MAGICVAL); |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
416 |
writeInt(ZIP64_MAGICVAL); |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
417 |
elen += 20; //headid(2) + size(2) + size(8) + csize(8) |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
418 |
} else { |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
419 |
writeInt(e.csize); // compressed size |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
420 |
writeInt(e.size); // uncompressed size |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
421 |
} |
2 | 422 |
} |
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
423 |
byte[] nameBytes = zc.getBytes(e.name); |
2 | 424 |
writeShort(nameBytes.length); |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
425 |
|
39772
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
426 |
int elenEXTT = 0; // info-zip extended timestamp |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
427 |
int flagEXTT = 0; |
39772
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
428 |
long umtime = -1; |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
429 |
long uatime = -1; |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
430 |
long uctime = -1; |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
431 |
if (e.mtime != null) { |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
432 |
elenEXTT += 4; |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
433 |
flagEXTT |= EXTT_FLAG_LMT; |
39772
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
434 |
umtime = fileTimeToUnixTime(e.mtime); |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
435 |
} |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
436 |
if (e.atime != null) { |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
437 |
elenEXTT += 4; |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
438 |
flagEXTT |= EXTT_FLAG_LAT; |
39772
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
439 |
uatime = fileTimeToUnixTime(e.atime); |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
440 |
} |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
441 |
if (e.ctime != null) { |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
442 |
elenEXTT += 4; |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
443 |
flagEXTT |= EXTT_FLAT_CT; |
39772
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
444 |
uctime = fileTimeToUnixTime(e.ctime); |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
445 |
} |
39772
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
446 |
if (flagEXTT != 0) { |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
447 |
// to use ntfs time if any m/a/ctime is beyond unixtime upper bound |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
448 |
if (umtime > UPPER_UNIXTIME_BOUND || |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
449 |
uatime > UPPER_UNIXTIME_BOUND || |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
450 |
uctime > UPPER_UNIXTIME_BOUND) { |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
451 |
elen += 36; // NTFS time, total 36 bytes |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
452 |
} else { |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
453 |
elen += (elenEXTT + 5); // headid(2) + size(2) + flag(1) + data |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
454 |
} |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
455 |
} |
2438
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
456 |
writeShort(elen); |
2 | 457 |
writeBytes(nameBytes, 0, nameBytes.length); |
2438
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
458 |
if (hasZip64) { |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
459 |
writeShort(ZIP64_EXTID); |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
460 |
writeShort(16); |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
461 |
writeLong(e.size); |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
462 |
writeLong(e.csize); |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
463 |
} |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
464 |
if (flagEXTT != 0) { |
39772
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
465 |
if (umtime > UPPER_UNIXTIME_BOUND || |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
466 |
uatime > UPPER_UNIXTIME_BOUND || |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
467 |
uctime > UPPER_UNIXTIME_BOUND) { |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
468 |
writeShort(EXTID_NTFS); // id |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
469 |
writeShort(32); // data size |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
470 |
writeInt(0); // reserved |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
471 |
writeShort(0x0001); // NTFS attr tag |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
472 |
writeShort(24); |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
473 |
writeLong(e.mtime == null ? WINDOWS_TIME_NOT_AVAILABLE |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
474 |
: fileTimeToWinTime(e.mtime)); |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
475 |
writeLong(e.atime == null ? WINDOWS_TIME_NOT_AVAILABLE |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
476 |
: fileTimeToWinTime(e.atime)); |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
477 |
writeLong(e.ctime == null ? WINDOWS_TIME_NOT_AVAILABLE |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
478 |
: fileTimeToWinTime(e.ctime)); |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
479 |
} else { |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
480 |
writeShort(EXTID_EXTT); |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
481 |
writeShort(elenEXTT + 1); // flag + data |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
482 |
writeByte(flagEXTT); |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
483 |
if (e.mtime != null) |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
484 |
writeInt(umtime); |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
485 |
if (e.atime != null) |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
486 |
writeInt(uatime); |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
487 |
if (e.ctime != null) |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
488 |
writeInt(uctime); |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
489 |
} |
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16713
diff
changeset
|
490 |
} |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
491 |
writeExtra(e.extra); |
2 | 492 |
locoff = written; |
493 |
} |
|
494 |
||
495 |
/* |
|
496 |
* Writes extra data descriptor (EXT) for specified entry. |
|
497 |
*/ |
|
498 |
private void writeEXT(ZipEntry e) throws IOException { |
|
499 |
writeInt(EXTSIG); // EXT header signature |
|
500 |
writeInt(e.crc); // crc-32 |
|
2438
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
501 |
if (e.csize >= ZIP64_MAGICVAL || e.size >= ZIP64_MAGICVAL) { |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
502 |
writeLong(e.csize); |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
503 |
writeLong(e.size); |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
504 |
} else { |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
505 |
writeInt(e.csize); // compressed size |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
506 |
writeInt(e.size); // uncompressed size |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
507 |
} |
2 | 508 |
} |
509 |
||
510 |
/* |
|
511 |
* Write central directory (CEN) header for specified entry. |
|
512 |
* REMIND: add support for file attributes |
|
513 |
*/ |
|
514 |
private void writeCEN(XEntry xentry) throws IOException { |
|
515 |
ZipEntry e = xentry.entry; |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
516 |
int flag = e.flag; |
2 | 517 |
int version = version(e); |
2438
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
518 |
long csize = e.csize; |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
519 |
long size = e.size; |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
520 |
long offset = xentry.offset; |
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16713
diff
changeset
|
521 |
int elenZIP64 = 0; |
2438
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
522 |
boolean hasZip64 = false; |
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16713
diff
changeset
|
523 |
|
2438
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
524 |
if (e.csize >= ZIP64_MAGICVAL) { |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
525 |
csize = ZIP64_MAGICVAL; |
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16713
diff
changeset
|
526 |
elenZIP64 += 8; // csize(8) |
2438
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
527 |
hasZip64 = true; |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
528 |
} |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
529 |
if (e.size >= ZIP64_MAGICVAL) { |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
530 |
size = ZIP64_MAGICVAL; // size(8) |
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16713
diff
changeset
|
531 |
elenZIP64 += 8; |
2438
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
532 |
hasZip64 = true; |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
533 |
} |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
534 |
if (xentry.offset >= ZIP64_MAGICVAL) { |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
535 |
offset = ZIP64_MAGICVAL; |
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16713
diff
changeset
|
536 |
elenZIP64 += 8; // offset(8) |
2438
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
537 |
hasZip64 = true; |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
538 |
} |
2 | 539 |
writeInt(CENSIG); // CEN header signature |
2438
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
540 |
if (hasZip64) { |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
541 |
writeShort(45); // ver 4.5 for zip64 |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
542 |
writeShort(45); |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
543 |
} else { |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
544 |
writeShort(version); // version made by |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
545 |
writeShort(version); // version needed to extract |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
546 |
} |
2 | 547 |
writeShort(flag); // general purpose bit flag |
548 |
writeShort(e.method); // compression method |
|
29226 | 549 |
writeInt(e.xdostime); // last modification time |
2 | 550 |
writeInt(e.crc); // crc-32 |
2438
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
551 |
writeInt(csize); // compressed size |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
552 |
writeInt(size); // uncompressed size |
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
553 |
byte[] nameBytes = zc.getBytes(e.name); |
2 | 554 |
writeShort(nameBytes.length); |
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16713
diff
changeset
|
555 |
|
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
556 |
int elen = getExtraLen(e.extra); |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
557 |
if (hasZip64) { |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
558 |
elen += (elenZIP64 + 4);// + headid(2) + datasize(2) |
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16713
diff
changeset
|
559 |
} |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
560 |
// cen info-zip extended timestamp only outputs mtime |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
561 |
// but set the flag for a/ctime, if present in loc |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
562 |
int flagEXTT = 0; |
39772
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
563 |
long umtime = -1; |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
564 |
long uatime = -1; |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
565 |
long uctime = -1; |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
566 |
if (e.mtime != null) { |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
567 |
flagEXTT |= EXTT_FLAG_LMT; |
39772
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
568 |
umtime = fileTimeToUnixTime(e.mtime); |
2438
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
569 |
} |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
570 |
if (e.atime != null) { |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
571 |
flagEXTT |= EXTT_FLAG_LAT; |
39772
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
572 |
uatime = fileTimeToUnixTime(e.atime); |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
573 |
} |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
574 |
if (e.ctime != null) { |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
575 |
flagEXTT |= EXTT_FLAT_CT; |
39772
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
576 |
uctime = fileTimeToUnixTime(e.ctime); |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
577 |
} |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
578 |
if (flagEXTT != 0) { |
39772
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
579 |
// to use ntfs time if any m/a/ctime is beyond unixtime upper bound |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
580 |
if (umtime > UPPER_UNIXTIME_BOUND || |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
581 |
uatime > UPPER_UNIXTIME_BOUND || |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
582 |
uctime > UPPER_UNIXTIME_BOUND) { |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
583 |
elen += 36; // NTFS time total 36 bytes |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
584 |
} else { |
50955
1acfd2f56d72
8206389: JarEntry.setCreation/LastAccessTime without setLastModifiedTime causes Invalid CEN header
sherman
parents:
50238
diff
changeset
|
585 |
elen += 5; // headid(2) + sz(2) + flag(1) |
1acfd2f56d72
8206389: JarEntry.setCreation/LastAccessTime without setLastModifiedTime causes Invalid CEN header
sherman
parents:
50238
diff
changeset
|
586 |
if (e.mtime != null) |
1acfd2f56d72
8206389: JarEntry.setCreation/LastAccessTime without setLastModifiedTime causes Invalid CEN header
sherman
parents:
50238
diff
changeset
|
587 |
elen += 4; // + mtime (4) |
39772
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
588 |
} |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
589 |
} |
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16713
diff
changeset
|
590 |
writeShort(elen); |
2 | 591 |
byte[] commentBytes; |
592 |
if (e.comment != null) { |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
593 |
commentBytes = zc.getBytes(e.comment); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
594 |
writeShort(Math.min(commentBytes.length, 0xffff)); |
2 | 595 |
} else { |
596 |
commentBytes = null; |
|
597 |
writeShort(0); |
|
598 |
} |
|
599 |
writeShort(0); // starting disk number |
|
600 |
writeShort(0); // internal file attributes (unused) |
|
601 |
writeInt(0); // external file attributes (unused) |
|
2438
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
602 |
writeInt(offset); // relative offset of local header |
2 | 603 |
writeBytes(nameBytes, 0, nameBytes.length); |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
604 |
|
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
605 |
// take care of EXTID_ZIP64 and EXTID_EXTT |
2438
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
606 |
if (hasZip64) { |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
607 |
writeShort(ZIP64_EXTID);// Zip64 extra |
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16713
diff
changeset
|
608 |
writeShort(elenZIP64); |
2438
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
609 |
if (size == ZIP64_MAGICVAL) |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
610 |
writeLong(e.size); |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
611 |
if (csize == ZIP64_MAGICVAL) |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
612 |
writeLong(e.csize); |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
613 |
if (offset == ZIP64_MAGICVAL) |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
614 |
writeLong(xentry.offset); |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
615 |
} |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
616 |
if (flagEXTT != 0) { |
39772
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
617 |
if (umtime > UPPER_UNIXTIME_BOUND || |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
618 |
uatime > UPPER_UNIXTIME_BOUND || |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
619 |
uctime > UPPER_UNIXTIME_BOUND) { |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
620 |
writeShort(EXTID_NTFS); // id |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
621 |
writeShort(32); // data size |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
622 |
writeInt(0); // reserved |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
623 |
writeShort(0x0001); // NTFS attr tag |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
624 |
writeShort(24); |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
625 |
writeLong(e.mtime == null ? WINDOWS_TIME_NOT_AVAILABLE |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
626 |
: fileTimeToWinTime(e.mtime)); |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
627 |
writeLong(e.atime == null ? WINDOWS_TIME_NOT_AVAILABLE |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
628 |
: fileTimeToWinTime(e.atime)); |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
629 |
writeLong(e.ctime == null ? WINDOWS_TIME_NOT_AVAILABLE |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
630 |
: fileTimeToWinTime(e.ctime)); |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
631 |
} else { |
39772
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
632 |
writeShort(EXTID_EXTT); |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
633 |
if (e.mtime != null) { |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
634 |
writeShort(5); // flag + mtime |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
635 |
writeByte(flagEXTT); |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
636 |
writeInt(umtime); |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
637 |
} else { |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
638 |
writeShort(1); // flag only |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
639 |
writeByte(flagEXTT); |
c2a5d2de5253
8161942: java.util.zip.ZipEntry.java not covering UpperLimit range of DOS epoch
sherman
parents:
37781
diff
changeset
|
640 |
} |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
641 |
} |
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16713
diff
changeset
|
642 |
} |
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
643 |
writeExtra(e.extra); |
2 | 644 |
if (commentBytes != null) { |
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
645 |
writeBytes(commentBytes, 0, Math.min(commentBytes.length, 0xffff)); |
2 | 646 |
} |
647 |
} |
|
648 |
||
649 |
/* |
|
650 |
* Writes end of central directory (END) header. |
|
651 |
*/ |
|
652 |
private void writeEND(long off, long len) throws IOException { |
|
2438
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
653 |
boolean hasZip64 = false; |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
654 |
long xlen = len; |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
655 |
long xoff = off; |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
656 |
if (xlen >= ZIP64_MAGICVAL) { |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
657 |
xlen = ZIP64_MAGICVAL; |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
658 |
hasZip64 = true; |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
659 |
} |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
660 |
if (xoff >= ZIP64_MAGICVAL) { |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
661 |
xoff = ZIP64_MAGICVAL; |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
662 |
hasZip64 = true; |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
663 |
} |
2 | 664 |
int count = xentries.size(); |
2438
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
665 |
if (count >= ZIP64_MAGICCOUNT) { |
16713
7824dded9821
8007905: To add a system property to create zip file without using ZIP64 end table when entry count > 64k
martin
parents:
14342
diff
changeset
|
666 |
hasZip64 |= !inhibitZip64; |
7824dded9821
8007905: To add a system property to create zip file without using ZIP64 end table when entry count > 64k
martin
parents:
14342
diff
changeset
|
667 |
if (hasZip64) { |
7824dded9821
8007905: To add a system property to create zip file without using ZIP64 end table when entry count > 64k
martin
parents:
14342
diff
changeset
|
668 |
count = ZIP64_MAGICCOUNT; |
7824dded9821
8007905: To add a system property to create zip file without using ZIP64 end table when entry count > 64k
martin
parents:
14342
diff
changeset
|
669 |
} |
2438
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
670 |
} |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
671 |
if (hasZip64) { |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
672 |
long off64 = written; |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
673 |
//zip64 end of central directory record |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
674 |
writeInt(ZIP64_ENDSIG); // zip64 END record signature |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
675 |
writeLong(ZIP64_ENDHDR - 12); // size of zip64 end |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
676 |
writeShort(45); // version made by |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
677 |
writeShort(45); // version needed to extract |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
678 |
writeInt(0); // number of this disk |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
679 |
writeInt(0); // central directory start disk |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
680 |
writeLong(xentries.size()); // number of directory entires on disk |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
681 |
writeLong(xentries.size()); // number of directory entires |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
682 |
writeLong(len); // length of central directory |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
683 |
writeLong(off); // offset of central directory |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
684 |
|
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
685 |
//zip64 end of central directory locator |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
686 |
writeInt(ZIP64_LOCSIG); // zip64 END locator signature |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
687 |
writeInt(0); // zip64 END start disk |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
688 |
writeLong(off64); // offset of zip64 END |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
689 |
writeInt(1); // total number of disks (?) |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
690 |
} |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
691 |
writeInt(ENDSIG); // END record signature |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
692 |
writeShort(0); // number of this disk |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
693 |
writeShort(0); // central directory start disk |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
694 |
writeShort(count); // number of directory entries on disk |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
695 |
writeShort(count); // total number of directory entries |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
696 |
writeInt(xlen); // length of central directory |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
697 |
writeInt(xoff); // offset of central directory |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
698 |
if (comment != null) { // zip file comment |
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
699 |
writeShort(comment.length); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2438
diff
changeset
|
700 |
writeBytes(comment, 0, comment.length); |
2 | 701 |
} else { |
702 |
writeShort(0); |
|
703 |
} |
|
704 |
} |
|
705 |
||
706 |
/* |
|
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
707 |
* Returns the length of extra data without EXTT and ZIP64. |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
708 |
*/ |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
709 |
private int getExtraLen(byte[] extra) { |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
710 |
if (extra == null) |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
711 |
return 0; |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
712 |
int skipped = 0; |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
713 |
int len = extra.length; |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
714 |
int off = 0; |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
715 |
while (off + 4 <= len) { |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
716 |
int tag = get16(extra, off); |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
717 |
int sz = get16(extra, off + 2); |
19608 | 718 |
if (sz < 0 || (off + 4 + sz) > len) { |
719 |
break; |
|
720 |
} |
|
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
721 |
if (tag == EXTID_EXTT || tag == EXTID_ZIP64) { |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
722 |
skipped += (sz + 4); |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
723 |
} |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
724 |
off += (sz + 4); |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
725 |
} |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
726 |
return len - skipped; |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
727 |
} |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
728 |
|
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
729 |
/* |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
730 |
* Writes extra data without EXTT and ZIP64. |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
731 |
* |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
732 |
* Extra timestamp and ZIP64 data is handled/output separately |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
733 |
* in writeLOC and writeCEN. |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
734 |
*/ |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
735 |
private void writeExtra(byte[] extra) throws IOException { |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
736 |
if (extra != null) { |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
737 |
int len = extra.length; |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
738 |
int off = 0; |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
739 |
while (off + 4 <= len) { |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
740 |
int tag = get16(extra, off); |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
741 |
int sz = get16(extra, off + 2); |
19608 | 742 |
if (sz < 0 || (off + 4 + sz) > len) { |
743 |
writeBytes(extra, off, len - off); |
|
744 |
return; |
|
745 |
} |
|
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
746 |
if (tag != EXTID_EXTT && tag != EXTID_ZIP64) { |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
747 |
writeBytes(extra, off, sz + 4); |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
748 |
} |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
749 |
off += (sz + 4); |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
750 |
} |
19608 | 751 |
if (off < len) { |
752 |
writeBytes(extra, off, len - off); |
|
753 |
} |
|
19374
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
754 |
} |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
755 |
} |
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
756 |
|
6773349693eb
8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents:
17910
diff
changeset
|
757 |
/* |
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16713
diff
changeset
|
758 |
* Writes a 8-bit byte to the output stream. |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16713
diff
changeset
|
759 |
*/ |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16713
diff
changeset
|
760 |
private void writeByte(int v) throws IOException { |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16713
diff
changeset
|
761 |
OutputStream out = this.out; |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16713
diff
changeset
|
762 |
out.write(v & 0xff); |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16713
diff
changeset
|
763 |
written += 1; |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16713
diff
changeset
|
764 |
} |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16713
diff
changeset
|
765 |
|
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16713
diff
changeset
|
766 |
/* |
2 | 767 |
* Writes a 16-bit short to the output stream in little-endian byte order. |
768 |
*/ |
|
769 |
private void writeShort(int v) throws IOException { |
|
770 |
OutputStream out = this.out; |
|
771 |
out.write((v >>> 0) & 0xff); |
|
772 |
out.write((v >>> 8) & 0xff); |
|
773 |
written += 2; |
|
774 |
} |
|
775 |
||
776 |
/* |
|
777 |
* Writes a 32-bit int to the output stream in little-endian byte order. |
|
778 |
*/ |
|
779 |
private void writeInt(long v) throws IOException { |
|
780 |
OutputStream out = this.out; |
|
781 |
out.write((int)((v >>> 0) & 0xff)); |
|
782 |
out.write((int)((v >>> 8) & 0xff)); |
|
783 |
out.write((int)((v >>> 16) & 0xff)); |
|
784 |
out.write((int)((v >>> 24) & 0xff)); |
|
785 |
written += 4; |
|
786 |
} |
|
787 |
||
788 |
/* |
|
2438
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
789 |
* Writes a 64-bit int to the output stream in little-endian byte order. |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
790 |
*/ |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
791 |
private void writeLong(long v) throws IOException { |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
792 |
OutputStream out = this.out; |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
793 |
out.write((int)((v >>> 0) & 0xff)); |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
794 |
out.write((int)((v >>> 8) & 0xff)); |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
795 |
out.write((int)((v >>> 16) & 0xff)); |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
796 |
out.write((int)((v >>> 24) & 0xff)); |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
797 |
out.write((int)((v >>> 32) & 0xff)); |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
798 |
out.write((int)((v >>> 40) & 0xff)); |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
799 |
out.write((int)((v >>> 48) & 0xff)); |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
800 |
out.write((int)((v >>> 56) & 0xff)); |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
801 |
written += 8; |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
802 |
} |
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
803 |
|
21c111b51aa8
4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
1228
diff
changeset
|
804 |
/* |
2 | 805 |
* Writes an array of bytes to the output stream. |
806 |
*/ |
|
807 |
private void writeBytes(byte[] b, int off, int len) throws IOException { |
|
808 |
super.out.write(b, off, len); |
|
809 |
written += len; |
|
810 |
} |
|
811 |
} |