author | sherman |
Fri, 01 May 2009 12:06:14 -0700 | |
changeset 2704 | a92617170304 |
parent 2592 | ef26f663a2ba |
child 2915 | 92e31faf9ffc |
permissions | -rw-r--r-- |
2 | 1 |
/* |
1158 | 2 |
* Copyright 1995-2008 Sun Microsystems, Inc. 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 |
|
7 |
* published by the Free Software Foundation. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
|
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 |
* |
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
||
26 |
package java.util.zip; |
|
27 |
||
28 |
import java.io.InputStream; |
|
29 |
import java.io.IOException; |
|
30 |
import java.io.EOFException; |
|
31 |
import java.io.File; |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
32 |
import java.nio.charset.Charset; |
2 | 33 |
import java.util.Vector; |
34 |
import java.util.Enumeration; |
|
35 |
import java.util.NoSuchElementException; |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
36 |
import static java.util.zip.ZipConstants64.*; |
2 | 37 |
|
38 |
/** |
|
39 |
* This class is used to read entries from a zip file. |
|
40 |
* |
|
41 |
* <p> Unless otherwise noted, passing a <tt>null</tt> argument to a constructor |
|
42 |
* or method in this class will cause a {@link NullPointerException} to be |
|
43 |
* thrown. |
|
44 |
* |
|
45 |
* @author David Connelly |
|
46 |
*/ |
|
47 |
public |
|
48 |
class ZipFile implements ZipConstants { |
|
49 |
private long jzfile; // address of jzfile data |
|
50 |
private String name; // zip file name |
|
51 |
private int total; // total number of entries |
|
52 |
private boolean closeRequested; |
|
53 |
||
54 |
private static final int STORED = ZipEntry.STORED; |
|
55 |
private static final int DEFLATED = ZipEntry.DEFLATED; |
|
56 |
||
57 |
/** |
|
58 |
* Mode flag to open a zip file for reading. |
|
59 |
*/ |
|
60 |
public static final int OPEN_READ = 0x1; |
|
61 |
||
62 |
/** |
|
63 |
* Mode flag to open a zip file and mark it for deletion. The file will be |
|
64 |
* deleted some time between the moment that it is opened and the moment |
|
65 |
* that it is closed, but its contents will remain accessible via the |
|
66 |
* <tt>ZipFile</tt> object until either the close method is invoked or the |
|
67 |
* virtual machine exits. |
|
68 |
*/ |
|
69 |
public static final int OPEN_DELETE = 0x4; |
|
70 |
||
71 |
static { |
|
72 |
/* Zip library is loaded from System.initializeSystemClass */ |
|
73 |
initIDs(); |
|
74 |
} |
|
75 |
||
76 |
private static native void initIDs(); |
|
77 |
||
78 |
/** |
|
79 |
* Opens a zip file for reading. |
|
80 |
* |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
81 |
* <p>First, if there is a security manager, its <code>checkRead</code> |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
82 |
* method is called with the <code>name</code> argument as its argument |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
83 |
* to ensure the read is allowed. |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
84 |
* |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
85 |
* <p>The UTF-8 {@link java.nio.charset.Charset charset} is used to |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
86 |
* decode the entry names and comments. |
2 | 87 |
* |
88 |
* @param name the name of the zip file |
|
89 |
* @throws ZipException if a ZIP format error has occurred |
|
90 |
* @throws IOException if an I/O error has occurred |
|
91 |
* @throws SecurityException if a security manager exists and its |
|
92 |
* <code>checkRead</code> method doesn't allow read access to the file. |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
93 |
* |
2 | 94 |
* @see SecurityManager#checkRead(java.lang.String) |
95 |
*/ |
|
96 |
public ZipFile(String name) throws IOException { |
|
97 |
this(new File(name), OPEN_READ); |
|
98 |
} |
|
99 |
||
100 |
/** |
|
101 |
* Opens a new <code>ZipFile</code> to read from the specified |
|
102 |
* <code>File</code> object in the specified mode. The mode argument |
|
103 |
* must be either <tt>OPEN_READ</tt> or <tt>OPEN_READ | OPEN_DELETE</tt>. |
|
104 |
* |
|
105 |
* <p>First, if there is a security manager, its <code>checkRead</code> |
|
106 |
* method is called with the <code>name</code> argument as its argument to |
|
107 |
* ensure the read is allowed. |
|
108 |
* |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
109 |
* <p>The UTF-8 {@link java.nio.charset.Charset charset} is used to |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
110 |
* decode the entry names and comments |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
111 |
* |
2 | 112 |
* @param file the ZIP file to be opened for reading |
113 |
* @param mode the mode in which the file is to be opened |
|
114 |
* @throws ZipException if a ZIP format error has occurred |
|
115 |
* @throws IOException if an I/O error has occurred |
|
116 |
* @throws SecurityException if a security manager exists and |
|
117 |
* its <code>checkRead</code> method |
|
118 |
* doesn't allow read access to the file, |
|
119 |
* or its <code>checkDelete</code> method doesn't allow deleting |
|
120 |
* the file when the <tt>OPEN_DELETE</tt> flag is set. |
|
121 |
* @throws IllegalArgumentException if the <tt>mode</tt> argument is invalid |
|
122 |
* @see SecurityManager#checkRead(java.lang.String) |
|
123 |
* @since 1.3 |
|
124 |
*/ |
|
125 |
public ZipFile(File file, int mode) throws IOException { |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
126 |
this(file, mode, Charset.forName("UTF-8")); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
127 |
} |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
128 |
|
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
129 |
/** |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
130 |
* Opens a ZIP file for reading given the specified File object. |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
131 |
* |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
132 |
* <p>The UTF-8 {@link java.nio.charset.Charset charset} is used to |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
133 |
* decode the entry names and comments. |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
134 |
* |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
135 |
* @param file the ZIP file to be opened for reading |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
136 |
* @throws ZipException if a ZIP format error has occurred |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
137 |
* @throws IOException if an I/O error has occurred |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
138 |
*/ |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
139 |
public ZipFile(File file) throws ZipException, IOException { |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
140 |
this(file, OPEN_READ); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
141 |
} |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
142 |
|
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
143 |
private ZipCoder zc; |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
144 |
|
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
145 |
/** |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
146 |
* Opens a new <code>ZipFile</code> to read from the specified |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
147 |
* <code>File</code> object in the specified mode. The mode argument |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
148 |
* must be either <tt>OPEN_READ</tt> or <tt>OPEN_READ | OPEN_DELETE</tt>. |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
149 |
* |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
150 |
* <p>First, if there is a security manager, its <code>checkRead</code> |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
151 |
* method is called with the <code>name</code> argument as its argument to |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
152 |
* ensure the read is allowed. |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
153 |
* |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
154 |
* @param file the ZIP file to be opened for reading |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
155 |
* @param mode the mode in which the file is to be opened |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
156 |
* @param charset |
2704
a92617170304
6836489: Incorrect @link usage in java.util.zip API doc
sherman
parents:
2592
diff
changeset
|
157 |
* the {@linkplain java.nio.charset.Charset charset} to |
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
158 |
* be used to decode the ZIP entry name and comment that are not |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
159 |
* encoded by using UTF-8 encoding (indicated by entry's general |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
160 |
* purpose flag). |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
161 |
* |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
162 |
* @throws ZipException if a ZIP format error has occurred |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
163 |
* @throws IOException if an I/O error has occurred |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
164 |
* |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
165 |
* @throws SecurityException |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
166 |
* if a security manager exists and its <code>checkRead</code> |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
167 |
* method doesn't allow read access to the file,or its |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
168 |
* <code>checkDelete</code> method doesn't allow deleting the |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
169 |
* file when the <tt>OPEN_DELETE</tt> flag is set |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
170 |
* |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
171 |
* @throws IllegalArgumentException if the <tt>mode</tt> argument is invalid |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
172 |
* |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
173 |
* @see SecurityManager#checkRead(java.lang.String) |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
174 |
* |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
175 |
* @since 1.7 |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
176 |
*/ |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
177 |
public ZipFile(File file, int mode, Charset charset) throws IOException |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
178 |
{ |
2 | 179 |
if (((mode & OPEN_READ) == 0) || |
180 |
((mode & ~(OPEN_READ | OPEN_DELETE)) != 0)) { |
|
181 |
throw new IllegalArgumentException("Illegal mode: 0x"+ |
|
182 |
Integer.toHexString(mode)); |
|
183 |
} |
|
184 |
String name = file.getPath(); |
|
185 |
SecurityManager sm = System.getSecurityManager(); |
|
186 |
if (sm != null) { |
|
187 |
sm.checkRead(name); |
|
188 |
if ((mode & OPEN_DELETE) != 0) { |
|
189 |
sm.checkDelete(name); |
|
190 |
} |
|
191 |
} |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
192 |
if (charset == null) |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
193 |
throw new NullPointerException("charset is null"); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
194 |
this.zc = ZipCoder.get(charset); |
2 | 195 |
jzfile = open(name, mode, file.lastModified()); |
196 |
this.name = name; |
|
197 |
this.total = getTotal(jzfile); |
|
198 |
} |
|
199 |
||
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
200 |
/** |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
201 |
* Opens a zip file for reading. |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
202 |
* |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
203 |
* <p>First, if there is a security manager, its <code>checkRead</code> |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
204 |
* method is called with the <code>name</code> argument as its argument |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
205 |
* to ensure the read is allowed. |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
206 |
* |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
207 |
* @param name the name of the zip file |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
208 |
* @param charset |
2704
a92617170304
6836489: Incorrect @link usage in java.util.zip API doc
sherman
parents:
2592
diff
changeset
|
209 |
* the {@linkplain java.nio.charset.Charset charset} to |
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
210 |
* be used to decode the ZIP entry name and comment that are not |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
211 |
* encoded by using UTF-8 encoding (indicated by entry's general |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
212 |
* purpose flag). |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
213 |
* |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
214 |
* @throws ZipException if a ZIP format error has occurred |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
215 |
* @throws IOException if an I/O error has occurred |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
216 |
* @throws SecurityException |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
217 |
* if a security manager exists and its <code>checkRead</code> |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
218 |
* method doesn't allow read access to the file |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
219 |
* |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
220 |
* @see SecurityManager#checkRead(java.lang.String) |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
221 |
* |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
222 |
* @since 1.7 |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
223 |
*/ |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
224 |
public ZipFile(String name, Charset charset) throws IOException |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
225 |
{ |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
226 |
this(new File(name), OPEN_READ, charset); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
227 |
} |
2 | 228 |
|
229 |
/** |
|
230 |
* Opens a ZIP file for reading given the specified File object. |
|
231 |
* @param file the ZIP file to be opened for reading |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
232 |
* @param charset |
2704
a92617170304
6836489: Incorrect @link usage in java.util.zip API doc
sherman
parents:
2592
diff
changeset
|
233 |
* The {@linkplain java.nio.charset.Charset charset} to be |
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
234 |
* used to decode the ZIP entry name and comment (ignored if |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
235 |
* the <a href="package-summary.html#lang_encoding"> language |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
236 |
* encoding bit</a> of the ZIP entry's general purpose bit |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
237 |
* flag is set). |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
238 |
* |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
239 |
* @throws ZipException if a ZIP format error has occurred |
2 | 240 |
* @throws IOException if an I/O error has occurred |
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
241 |
* |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
242 |
* @since 1.7 |
2 | 243 |
*/ |
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
244 |
public ZipFile(File file, Charset charset) throws IOException |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
245 |
{ |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
246 |
this(file, OPEN_READ, charset); |
2 | 247 |
} |
248 |
||
249 |
/** |
|
250 |
* Returns the zip file entry for the specified name, or null |
|
251 |
* if not found. |
|
252 |
* |
|
253 |
* @param name the name of the entry |
|
254 |
* @return the zip file entry, or null if not found |
|
255 |
* @throws IllegalStateException if the zip file has been closed |
|
256 |
*/ |
|
257 |
public ZipEntry getEntry(String name) { |
|
258 |
if (name == null) { |
|
259 |
throw new NullPointerException("name"); |
|
260 |
} |
|
261 |
long jzentry = 0; |
|
262 |
synchronized (this) { |
|
263 |
ensureOpen(); |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
264 |
jzentry = getEntry(jzfile, zc.getBytes(name), true); |
2 | 265 |
if (jzentry != 0) { |
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
266 |
ZipEntry ze = getZipEntry(name, jzentry); |
2 | 267 |
freeEntry(jzfile, jzentry); |
268 |
return ze; |
|
269 |
} |
|
270 |
} |
|
271 |
return null; |
|
272 |
} |
|
273 |
||
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
274 |
private static native long getEntry(long jzfile, byte[] name, |
2 | 275 |
boolean addSlash); |
276 |
||
277 |
// freeEntry releases the C jzentry struct. |
|
278 |
private static native void freeEntry(long jzfile, long jzentry); |
|
279 |
||
280 |
/** |
|
281 |
* Returns an input stream for reading the contents of the specified |
|
282 |
* zip file entry. |
|
283 |
* |
|
284 |
* <p> Closing this ZIP file will, in turn, close all input |
|
285 |
* streams that have been returned by invocations of this method. |
|
286 |
* |
|
287 |
* @param entry the zip file entry |
|
288 |
* @return the input stream for reading the contents of the specified |
|
289 |
* zip file entry. |
|
290 |
* @throws ZipException if a ZIP format error has occurred |
|
291 |
* @throws IOException if an I/O error has occurred |
|
292 |
* @throws IllegalStateException if the zip file has been closed |
|
293 |
*/ |
|
294 |
public InputStream getInputStream(ZipEntry entry) throws IOException { |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
295 |
if (entry == null) { |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
296 |
throw new NullPointerException("entry"); |
2 | 297 |
} |
298 |
long jzentry = 0; |
|
299 |
ZipFileInputStream in = null; |
|
300 |
synchronized (this) { |
|
301 |
ensureOpen(); |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
302 |
if (!zc.isUTF8() && (entry.flag & EFS) != 0) { |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
303 |
jzentry = getEntry(jzfile, zc.getBytesUTF8(entry.name), false); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
304 |
} else { |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
305 |
jzentry = getEntry(jzfile, zc.getBytes(entry.name), false); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
306 |
} |
2 | 307 |
if (jzentry == 0) { |
308 |
return null; |
|
309 |
} |
|
310 |
in = new ZipFileInputStream(jzentry); |
|
311 |
} |
|
312 |
final ZipFileInputStream zfin = in; |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
313 |
switch (getEntryMethod(jzentry)) { |
2 | 314 |
case STORED: |
315 |
return zfin; |
|
316 |
case DEFLATED: |
|
317 |
// MORE: Compute good size for inflater stream: |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
318 |
long size = getEntrySize(jzentry) + 2; // Inflater likes a bit of slack |
2 | 319 |
if (size > 65536) size = 8192; |
320 |
if (size <= 0) size = 4096; |
|
321 |
return new InflaterInputStream(zfin, getInflater(), (int)size) { |
|
322 |
private boolean isClosed = false; |
|
323 |
||
324 |
public void close() throws IOException { |
|
325 |
if (!isClosed) { |
|
326 |
releaseInflater(inf); |
|
327 |
this.in.close(); |
|
328 |
isClosed = true; |
|
329 |
} |
|
330 |
} |
|
331 |
// Override fill() method to provide an extra "dummy" byte |
|
332 |
// at the end of the input stream. This is required when |
|
333 |
// using the "nowrap" Inflater option. |
|
334 |
protected void fill() throws IOException { |
|
335 |
if (eof) { |
|
336 |
throw new EOFException( |
|
337 |
"Unexpected end of ZLIB input stream"); |
|
338 |
} |
|
339 |
len = this.in.read(buf, 0, buf.length); |
|
340 |
if (len == -1) { |
|
341 |
buf[0] = 0; |
|
342 |
len = 1; |
|
343 |
eof = true; |
|
344 |
} |
|
345 |
inf.setInput(buf, 0, len); |
|
346 |
} |
|
347 |
private boolean eof; |
|
348 |
||
349 |
public int available() throws IOException { |
|
350 |
if (isClosed) |
|
351 |
return 0; |
|
352 |
long avail = zfin.size() - inf.getBytesWritten(); |
|
353 |
return avail > (long) Integer.MAX_VALUE ? |
|
354 |
Integer.MAX_VALUE : (int) avail; |
|
355 |
} |
|
356 |
}; |
|
357 |
default: |
|
358 |
throw new ZipException("invalid compression method"); |
|
359 |
} |
|
360 |
} |
|
361 |
||
362 |
/* |
|
363 |
* Gets an inflater from the list of available inflaters or allocates |
|
364 |
* a new one. |
|
365 |
*/ |
|
366 |
private Inflater getInflater() { |
|
367 |
synchronized (inflaters) { |
|
368 |
int size = inflaters.size(); |
|
369 |
if (size > 0) { |
|
370 |
Inflater inf = (Inflater)inflaters.remove(size - 1); |
|
371 |
return inf; |
|
372 |
} else { |
|
373 |
return new Inflater(true); |
|
374 |
} |
|
375 |
} |
|
376 |
} |
|
377 |
||
378 |
/* |
|
379 |
* Releases the specified inflater to the list of available inflaters. |
|
380 |
*/ |
|
381 |
private void releaseInflater(Inflater inf) { |
|
382 |
synchronized (inflaters) { |
|
1158 | 383 |
inf.reset(); |
2 | 384 |
inflaters.add(inf); |
385 |
} |
|
386 |
} |
|
387 |
||
388 |
// List of available Inflater objects for decompression |
|
389 |
private Vector inflaters = new Vector(); |
|
390 |
||
391 |
/** |
|
392 |
* Returns the path name of the ZIP file. |
|
393 |
* @return the path name of the ZIP file |
|
394 |
*/ |
|
395 |
public String getName() { |
|
396 |
return name; |
|
397 |
} |
|
398 |
||
399 |
/** |
|
400 |
* Returns an enumeration of the ZIP file entries. |
|
401 |
* @return an enumeration of the ZIP file entries |
|
402 |
* @throws IllegalStateException if the zip file has been closed |
|
403 |
*/ |
|
404 |
public Enumeration<? extends ZipEntry> entries() { |
|
405 |
ensureOpen(); |
|
406 |
return new Enumeration<ZipEntry>() { |
|
407 |
private int i = 0; |
|
408 |
public boolean hasMoreElements() { |
|
409 |
synchronized (ZipFile.this) { |
|
410 |
ensureOpen(); |
|
411 |
return i < total; |
|
412 |
} |
|
413 |
} |
|
414 |
public ZipEntry nextElement() throws NoSuchElementException { |
|
415 |
synchronized (ZipFile.this) { |
|
416 |
ensureOpen(); |
|
417 |
if (i >= total) { |
|
418 |
throw new NoSuchElementException(); |
|
419 |
} |
|
420 |
long jzentry = getNextEntry(jzfile, i++); |
|
421 |
if (jzentry == 0) { |
|
422 |
String message; |
|
423 |
if (closeRequested) { |
|
424 |
message = "ZipFile concurrently closed"; |
|
425 |
} else { |
|
426 |
message = getZipMessage(ZipFile.this.jzfile); |
|
427 |
} |
|
428 |
throw new ZipError("jzentry == 0" + |
|
429 |
",\n jzfile = " + ZipFile.this.jzfile + |
|
430 |
",\n total = " + ZipFile.this.total + |
|
431 |
",\n name = " + ZipFile.this.name + |
|
432 |
",\n i = " + i + |
|
433 |
",\n message = " + message |
|
434 |
); |
|
435 |
} |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
436 |
ZipEntry ze = getZipEntry(null, jzentry); |
2 | 437 |
freeEntry(jzfile, jzentry); |
438 |
return ze; |
|
439 |
} |
|
440 |
} |
|
441 |
}; |
|
442 |
} |
|
443 |
||
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
444 |
private ZipEntry getZipEntry(String name, long jzentry) { |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
445 |
ZipEntry e = new ZipEntry(); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
446 |
e.flag = getEntryFlag(jzentry); // get the flag first |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
447 |
if (name != null) { |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
448 |
e.name = name; |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
449 |
} else { |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
450 |
byte[] bname = getEntryBytes(jzentry, JZENTRY_NAME); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
451 |
if (!zc.isUTF8() && (e.flag & EFS) != 0) { |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
452 |
e.name = zc.toStringUTF8(bname, bname.length); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
453 |
} else { |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
454 |
e.name = zc.toString(bname, bname.length); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
455 |
} |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
456 |
} |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
457 |
e.time = getEntryTime(jzentry); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
458 |
e.crc = getEntryCrc(jzentry); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
459 |
e.size = getEntrySize(jzentry); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
460 |
e. csize = getEntryCSize(jzentry); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
461 |
e.method = getEntryMethod(jzentry); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
462 |
e.extra = getEntryBytes(jzentry, JZENTRY_EXTRA); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
463 |
byte[] bcomm = getEntryBytes(jzentry, JZENTRY_COMMENT); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
464 |
if (bcomm == null) { |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
465 |
e.comment = null; |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
466 |
} else { |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
467 |
if (!zc.isUTF8() && (e.flag & EFS) != 0) { |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
468 |
e.comment = zc.toStringUTF8(bcomm, bcomm.length); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
469 |
} else { |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
470 |
e.comment = zc.toString(bcomm, bcomm.length); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
471 |
} |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
472 |
} |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
473 |
return e; |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
474 |
} |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
475 |
|
2 | 476 |
private static native long getNextEntry(long jzfile, int i); |
477 |
||
478 |
/** |
|
479 |
* Returns the number of entries in the ZIP file. |
|
480 |
* @return the number of entries in the ZIP file |
|
481 |
* @throws IllegalStateException if the zip file has been closed |
|
482 |
*/ |
|
483 |
public int size() { |
|
484 |
ensureOpen(); |
|
485 |
return total; |
|
486 |
} |
|
487 |
||
488 |
/** |
|
489 |
* Closes the ZIP file. |
|
490 |
* <p> Closing this ZIP file will close all of the input streams |
|
491 |
* previously returned by invocations of the {@link #getInputStream |
|
492 |
* getInputStream} method. |
|
493 |
* |
|
494 |
* @throws IOException if an I/O error has occurred |
|
495 |
*/ |
|
496 |
public void close() throws IOException { |
|
497 |
synchronized (this) { |
|
498 |
closeRequested = true; |
|
499 |
||
500 |
if (jzfile != 0) { |
|
501 |
// Close the zip file |
|
502 |
long zf = this.jzfile; |
|
503 |
jzfile = 0; |
|
504 |
||
505 |
close(zf); |
|
506 |
||
507 |
// Release inflaters |
|
508 |
synchronized (inflaters) { |
|
509 |
int size = inflaters.size(); |
|
510 |
for (int i = 0; i < size; i++) { |
|
511 |
Inflater inf = (Inflater)inflaters.get(i); |
|
512 |
inf.end(); |
|
513 |
} |
|
514 |
} |
|
515 |
} |
|
516 |
} |
|
517 |
} |
|
518 |
||
519 |
||
520 |
/** |
|
521 |
* Ensures that the <code>close</code> method of this ZIP file is |
|
522 |
* called when there are no more references to it. |
|
523 |
* |
|
524 |
* <p> |
|
525 |
* Since the time when GC would invoke this method is undetermined, |
|
526 |
* it is strongly recommended that applications invoke the <code>close</code> |
|
527 |
* method as soon they have finished accessing this <code>ZipFile</code>. |
|
528 |
* This will prevent holding up system resources for an undetermined |
|
529 |
* length of time. |
|
530 |
* |
|
531 |
* @throws IOException if an I/O error has occurred |
|
532 |
* @see java.util.zip.ZipFile#close() |
|
533 |
*/ |
|
534 |
protected void finalize() throws IOException { |
|
535 |
close(); |
|
536 |
} |
|
537 |
||
538 |
private static native void close(long jzfile); |
|
539 |
||
540 |
private void ensureOpen() { |
|
541 |
if (closeRequested) { |
|
542 |
throw new IllegalStateException("zip file closed"); |
|
543 |
} |
|
544 |
||
545 |
if (jzfile == 0) { |
|
546 |
throw new IllegalStateException("The object is not initialized."); |
|
547 |
} |
|
548 |
} |
|
549 |
||
550 |
private void ensureOpenOrZipException() throws IOException { |
|
551 |
if (closeRequested) { |
|
552 |
throw new ZipException("ZipFile closed"); |
|
553 |
} |
|
554 |
} |
|
555 |
||
556 |
/* |
|
557 |
* Inner class implementing the input stream used to read a |
|
558 |
* (possibly compressed) zip file entry. |
|
559 |
*/ |
|
560 |
private class ZipFileInputStream extends InputStream { |
|
561 |
protected long jzentry; // address of jzentry data |
|
562 |
private long pos; // current position within entry data |
|
563 |
protected long rem; // number of remaining bytes within entry |
|
564 |
protected long size; // uncompressed size of this entry |
|
565 |
||
566 |
ZipFileInputStream(long jzentry) { |
|
567 |
pos = 0; |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
568 |
rem = getEntryCSize(jzentry); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
569 |
size = getEntrySize(jzentry); |
2 | 570 |
this.jzentry = jzentry; |
571 |
} |
|
572 |
||
573 |
public int read(byte b[], int off, int len) throws IOException { |
|
574 |
if (rem == 0) { |
|
575 |
return -1; |
|
576 |
} |
|
577 |
if (len <= 0) { |
|
578 |
return 0; |
|
579 |
} |
|
580 |
if (len > rem) { |
|
581 |
len = (int) rem; |
|
582 |
} |
|
583 |
synchronized (ZipFile.this) { |
|
584 |
ensureOpenOrZipException(); |
|
585 |
||
586 |
len = ZipFile.read(ZipFile.this.jzfile, jzentry, pos, b, |
|
587 |
off, len); |
|
588 |
} |
|
589 |
if (len > 0) { |
|
590 |
pos += len; |
|
591 |
rem -= len; |
|
592 |
} |
|
593 |
if (rem == 0) { |
|
594 |
close(); |
|
595 |
} |
|
596 |
return len; |
|
597 |
} |
|
598 |
||
599 |
public int read() throws IOException { |
|
600 |
byte[] b = new byte[1]; |
|
601 |
if (read(b, 0, 1) == 1) { |
|
602 |
return b[0] & 0xff; |
|
603 |
} else { |
|
604 |
return -1; |
|
605 |
} |
|
606 |
} |
|
607 |
||
608 |
public long skip(long n) { |
|
609 |
if (n > rem) |
|
610 |
n = rem; |
|
611 |
pos += n; |
|
612 |
rem -= n; |
|
613 |
if (rem == 0) { |
|
614 |
close(); |
|
615 |
} |
|
616 |
return n; |
|
617 |
} |
|
618 |
||
619 |
public int available() { |
|
620 |
return rem > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) rem; |
|
621 |
} |
|
622 |
||
623 |
public long size() { |
|
624 |
return size; |
|
625 |
} |
|
626 |
||
627 |
public void close() { |
|
628 |
rem = 0; |
|
629 |
synchronized (ZipFile.this) { |
|
630 |
if (jzentry != 0 && ZipFile.this.jzfile != 0) { |
|
631 |
freeEntry(ZipFile.this.jzfile, jzentry); |
|
632 |
jzentry = 0; |
|
633 |
} |
|
634 |
} |
|
635 |
} |
|
636 |
||
637 |
} |
|
638 |
||
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
639 |
|
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
640 |
private static native long open(String name, int mode, long lastModified) |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
641 |
throws IOException; |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
642 |
private static native int getTotal(long jzfile); |
2 | 643 |
private static native int read(long jzfile, long jzentry, |
644 |
long pos, byte[] b, int off, int len); |
|
645 |
||
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
646 |
// access to the native zentry object |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
647 |
private static native long getEntryTime(long jzentry); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
648 |
private static native long getEntryCrc(long jzentry); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
649 |
private static native long getEntryCSize(long jzentry); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
650 |
private static native long getEntrySize(long jzentry); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
651 |
private static native int getEntryMethod(long jzentry); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
652 |
private static native int getEntryFlag(long jzentry); |
2 | 653 |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
654 |
private static final int JZENTRY_NAME = 0; |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
655 |
private static final int JZENTRY_EXTRA = 1; |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
656 |
private static final int JZENTRY_COMMENT = 2; |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
1158
diff
changeset
|
657 |
private static native byte[] getEntryBytes(long jzentry, int type); |
2 | 658 |
|
659 |
private static native String getZipMessage(long jzfile); |
|
660 |
} |