author | alanb |
Fri, 02 Nov 2012 15:50:11 +0000 | |
changeset 14342 | 8435a30053c1 |
parent 12543 | b77bc2f404ba |
child 18223 | 35a5c2462991 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
14342
8435a30053c1
7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents:
12543
diff
changeset
|
2 |
* Copyright (c) 1998, 2012, 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 |
/* |
|
27 |
* Native method support for java.util.zip.ZipFile |
|
28 |
*/ |
|
29 |
||
30 |
#include <stdio.h> |
|
31 |
#include <stdlib.h> |
|
32 |
#include <string.h> |
|
33 |
#include <errno.h> |
|
34 |
#include <ctype.h> |
|
35 |
#include <assert.h> |
|
36 |
#include "jlong.h" |
|
37 |
#include "jvm.h" |
|
38 |
#include "jni.h" |
|
39 |
#include "jni_util.h" |
|
40 |
#include "zip_util.h" |
|
41 |
#ifdef WIN32 |
|
42 |
#include "io_util_md.h" |
|
3078 | 43 |
#else |
44 |
#include "io_util.h" |
|
2 | 45 |
#endif |
46 |
||
47 |
#include "java_util_zip_ZipFile.h" |
|
48 |
#include "java_util_jar_JarFile.h" |
|
49 |
||
50 |
#define DEFLATED 8 |
|
51 |
#define STORED 0 |
|
52 |
||
53 |
static jfieldID jzfileID; |
|
54 |
||
55 |
static int OPEN_READ = java_util_zip_ZipFile_OPEN_READ; |
|
56 |
static int OPEN_DELETE = java_util_zip_ZipFile_OPEN_DELETE; |
|
57 |
||
58 |
JNIEXPORT void JNICALL |
|
59 |
Java_java_util_zip_ZipFile_initIDs(JNIEnv *env, jclass cls) |
|
60 |
{ |
|
61 |
jzfileID = (*env)->GetFieldID(env, cls, "jzfile", "J"); |
|
62 |
assert(jzfileID != 0); |
|
63 |
} |
|
64 |
||
65 |
static void |
|
66 |
ThrowZipException(JNIEnv *env, const char *msg) |
|
67 |
{ |
|
68 |
jstring s = NULL; |
|
69 |
jobject x; |
|
70 |
||
71 |
if (msg != NULL) { |
|
72 |
s = JNU_NewStringPlatform(env, msg); |
|
73 |
} |
|
74 |
x = JNU_NewObjectByName(env, |
|
75 |
"java/util/zip/ZipException", |
|
76 |
"(Ljava/lang/String;)V", s); |
|
77 |
if (x != NULL) { |
|
78 |
(*env)->Throw(env, x); |
|
79 |
} |
|
80 |
} |
|
81 |
||
82 |
JNIEXPORT jlong JNICALL |
|
83 |
Java_java_util_zip_ZipFile_open(JNIEnv *env, jclass cls, jstring name, |
|
5148
2bf5469864ea
6929479: Add a system property sun.zip.disableMemoryMapping to disable mmap use in ZipFile
sherman
parents:
3078
diff
changeset
|
84 |
jint mode, jlong lastModified, |
2bf5469864ea
6929479: Add a system property sun.zip.disableMemoryMapping to disable mmap use in ZipFile
sherman
parents:
3078
diff
changeset
|
85 |
jboolean usemmap) |
2 | 86 |
{ |
87 |
const char *path = JNU_GetStringPlatformChars(env, name, 0); |
|
88 |
char *msg = 0; |
|
89 |
jlong result = 0; |
|
90 |
int flag = 0; |
|
91 |
jzfile *zip = 0; |
|
92 |
||
93 |
if (mode & OPEN_READ) flag |= O_RDONLY; |
|
94 |
if (mode & OPEN_DELETE) flag |= JVM_O_DELETE; |
|
95 |
||
96 |
if (path != 0) { |
|
97 |
zip = ZIP_Get_From_Cache(path, &msg, lastModified); |
|
98 |
if (zip == 0 && msg == 0) { |
|
99 |
ZFILE zfd = 0; |
|
100 |
#ifdef WIN32 |
|
101 |
zfd = winFileHandleOpen(env, name, flag); |
|
102 |
if (zfd == -1) { |
|
103 |
/* Exception already pending. */ |
|
104 |
goto finally; |
|
105 |
} |
|
106 |
#else |
|
107 |
zfd = JVM_Open(path, flag, 0); |
|
3078 | 108 |
if (zfd < 0) { |
109 |
throwFileNotFoundException(env, name); |
|
110 |
goto finally; |
|
111 |
} |
|
2 | 112 |
#endif |
5148
2bf5469864ea
6929479: Add a system property sun.zip.disableMemoryMapping to disable mmap use in ZipFile
sherman
parents:
3078
diff
changeset
|
113 |
zip = ZIP_Put_In_Cache0(path, zfd, &msg, lastModified, usemmap); |
2 | 114 |
} |
115 |
||
116 |
if (zip != 0) { |
|
117 |
result = ptr_to_jlong(zip); |
|
118 |
} else if (msg != 0) { |
|
119 |
ThrowZipException(env, msg); |
|
12543
b77bc2f404ba
7159982: ZipFile uses static for error message when malformed zip file encountered
zhouyx
parents:
7668
diff
changeset
|
120 |
free(msg); |
2 | 121 |
} else if (errno == ENOMEM) { |
122 |
JNU_ThrowOutOfMemoryError(env, 0); |
|
123 |
} else { |
|
124 |
ThrowZipException(env, "error in opening zip file"); |
|
125 |
} |
|
126 |
finally: |
|
127 |
JNU_ReleaseStringPlatformChars(env, name, path); |
|
128 |
} |
|
129 |
return result; |
|
130 |
} |
|
131 |
||
132 |
JNIEXPORT jint JNICALL |
|
133 |
Java_java_util_zip_ZipFile_getTotal(JNIEnv *env, jclass cls, jlong zfile) |
|
134 |
{ |
|
135 |
jzfile *zip = jlong_to_ptr(zfile); |
|
136 |
||
137 |
return zip->total; |
|
138 |
} |
|
139 |
||
140 |
JNIEXPORT void JNICALL |
|
141 |
Java_java_util_zip_ZipFile_close(JNIEnv *env, jclass cls, jlong zfile) |
|
142 |
{ |
|
143 |
ZIP_Close(jlong_to_ptr(zfile)); |
|
144 |
} |
|
145 |
||
146 |
JNIEXPORT jlong JNICALL |
|
147 |
Java_java_util_zip_ZipFile_getEntry(JNIEnv *env, jclass cls, jlong zfile, |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
148 |
jbyteArray name, jboolean addSlash) |
2 | 149 |
{ |
150 |
#define MAXNAME 1024 |
|
151 |
jzfile *zip = jlong_to_ptr(zfile); |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
152 |
jsize ulen = (*env)->GetArrayLength(env, name); |
2 | 153 |
char buf[MAXNAME+2], *path; |
154 |
jzentry *ze; |
|
155 |
||
156 |
if (ulen > MAXNAME) { |
|
157 |
path = malloc(ulen + 2); |
|
158 |
if (path == 0) { |
|
159 |
JNU_ThrowOutOfMemoryError(env, 0); |
|
160 |
return 0; |
|
161 |
} |
|
162 |
} else { |
|
163 |
path = buf; |
|
164 |
} |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
165 |
(*env)->GetByteArrayRegion(env, name, 0, ulen, (jbyte *)path); |
2 | 166 |
path[ulen] = '\0'; |
167 |
if (addSlash == JNI_FALSE) { |
|
168 |
ze = ZIP_GetEntry(zip, path, 0); |
|
169 |
} else { |
|
170 |
ze = ZIP_GetEntry(zip, path, (jint)ulen); |
|
171 |
} |
|
172 |
if (path != buf) { |
|
173 |
free(path); |
|
174 |
} |
|
175 |
return ptr_to_jlong(ze); |
|
176 |
} |
|
177 |
||
178 |
JNIEXPORT void JNICALL |
|
179 |
Java_java_util_zip_ZipFile_freeEntry(JNIEnv *env, jclass cls, jlong zfile, |
|
180 |
jlong zentry) |
|
181 |
{ |
|
182 |
jzfile *zip = jlong_to_ptr(zfile); |
|
183 |
jzentry *ze = jlong_to_ptr(zentry); |
|
184 |
ZIP_FreeEntry(zip, ze); |
|
185 |
} |
|
186 |
||
187 |
JNIEXPORT jlong JNICALL |
|
188 |
Java_java_util_zip_ZipFile_getNextEntry(JNIEnv *env, jclass cls, jlong zfile, |
|
189 |
jint n) |
|
190 |
{ |
|
191 |
jzentry *ze = ZIP_GetNextEntry(jlong_to_ptr(zfile), n); |
|
192 |
return ptr_to_jlong(ze); |
|
193 |
} |
|
194 |
||
195 |
JNIEXPORT jint JNICALL |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
196 |
Java_java_util_zip_ZipFile_getEntryMethod(JNIEnv *env, jclass cls, jlong zentry) |
2 | 197 |
{ |
198 |
jzentry *ze = jlong_to_ptr(zentry); |
|
199 |
return ze->csize != 0 ? DEFLATED : STORED; |
|
200 |
} |
|
201 |
||
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
202 |
JNIEXPORT jint JNICALL |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
203 |
Java_java_util_zip_ZipFile_getEntryFlag(JNIEnv *env, jclass cls, jlong zentry) |
2 | 204 |
{ |
205 |
jzentry *ze = jlong_to_ptr(zentry); |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
206 |
return ze->flag; |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
207 |
} |
2 | 208 |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
209 |
JNIEXPORT jlong JNICALL |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
210 |
Java_java_util_zip_ZipFile_getEntryCSize(JNIEnv *env, jclass cls, jlong zentry) |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
211 |
{ |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
212 |
jzentry *ze = jlong_to_ptr(zentry); |
2 | 213 |
return ze->csize != 0 ? ze->csize : ze->size; |
214 |
} |
|
215 |
||
216 |
JNIEXPORT jlong JNICALL |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
217 |
Java_java_util_zip_ZipFile_getEntrySize(JNIEnv *env, jclass cls, jlong zentry) |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
218 |
{ |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
219 |
jzentry *ze = jlong_to_ptr(zentry); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
220 |
return ze->size; |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
221 |
} |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
222 |
|
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
223 |
JNIEXPORT jlong JNICALL |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
224 |
Java_java_util_zip_ZipFile_getEntryTime(JNIEnv *env, jclass cls, jlong zentry) |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
225 |
{ |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
226 |
jzentry *ze = jlong_to_ptr(zentry); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
227 |
return (jlong)ze->time & 0xffffffffUL; |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
228 |
} |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
229 |
|
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
230 |
JNIEXPORT jlong JNICALL |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
231 |
Java_java_util_zip_ZipFile_getEntryCrc(JNIEnv *env, jclass cls, jlong zentry) |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
232 |
{ |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
233 |
jzentry *ze = jlong_to_ptr(zentry); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
234 |
return (jlong)ze->crc & 0xffffffffUL; |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
235 |
} |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
236 |
|
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
237 |
JNIEXPORT jbyteArray JNICALL |
3078 | 238 |
Java_java_util_zip_ZipFile_getCommentBytes(JNIEnv *env, |
239 |
jclass cls, |
|
240 |
jlong zfile) |
|
241 |
{ |
|
242 |
jzfile *zip = jlong_to_ptr(zfile); |
|
243 |
jbyteArray jba = NULL; |
|
244 |
||
245 |
if (zip->comment != NULL) { |
|
246 |
if ((jba = (*env)->NewByteArray(env, zip->clen)) == NULL) |
|
247 |
return NULL; |
|
248 |
(*env)->SetByteArrayRegion(env, jba, 0, zip->clen, (jbyte*)zip->comment); |
|
249 |
} |
|
250 |
return jba; |
|
251 |
} |
|
252 |
||
253 |
JNIEXPORT jbyteArray JNICALL |
|
254 |
Java_java_util_zip_ZipFile_getEntryBytes(JNIEnv *env, |
|
255 |
jclass cls, |
|
256 |
jlong zentry, jint type) |
|
2 | 257 |
{ |
258 |
jzentry *ze = jlong_to_ptr(zentry); |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
259 |
int len = 0; |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
260 |
jbyteArray jba = NULL; |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
261 |
switch (type) { |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
262 |
case java_util_zip_ZipFile_JZENTRY_NAME: |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
263 |
if (ze->name != 0) { |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
264 |
len = (int)strlen(ze->name); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
265 |
if (len == 0 || (jba = (*env)->NewByteArray(env, len)) == NULL) |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
266 |
break; |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
267 |
(*env)->SetByteArrayRegion(env, jba, 0, len, (jbyte *)ze->name); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
268 |
} |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
269 |
break; |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
270 |
case java_util_zip_ZipFile_JZENTRY_EXTRA: |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
271 |
if (ze->extra != 0) { |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
272 |
unsigned char *bp = (unsigned char *)&ze->extra[0]; |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
273 |
len = (bp[0] | (bp[1] << 8)); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
274 |
if (len <= 0 || (jba = (*env)->NewByteArray(env, len)) == NULL) |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
275 |
break; |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
276 |
(*env)->SetByteArrayRegion(env, jba, 0, len, &ze->extra[2]); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
277 |
} |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
278 |
break; |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
279 |
case java_util_zip_ZipFile_JZENTRY_COMMENT: |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
280 |
if (ze->comment != 0) { |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
281 |
len = (int)strlen(ze->comment); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
282 |
if (len == 0 || (jba = (*env)->NewByteArray(env, len)) == NULL) |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
283 |
break; |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
284 |
(*env)->SetByteArrayRegion(env, jba, 0, len, (jbyte*)ze->comment); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
285 |
} |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
286 |
break; |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
287 |
} |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
288 |
return jba; |
2 | 289 |
} |
290 |
||
291 |
JNIEXPORT jint JNICALL |
|
292 |
Java_java_util_zip_ZipFile_read(JNIEnv *env, jclass cls, jlong zfile, |
|
293 |
jlong zentry, jlong pos, jbyteArray bytes, |
|
294 |
jint off, jint len) |
|
295 |
{ |
|
296 |
jzfile *zip = jlong_to_ptr(zfile); |
|
297 |
char *msg; |
|
298 |
||
299 |
#define BUFSIZE 8192 |
|
300 |
/* copy via tmp stack buffer: */ |
|
301 |
jbyte buf[BUFSIZE]; |
|
302 |
||
303 |
if (len > BUFSIZE) { |
|
304 |
len = BUFSIZE; |
|
305 |
} |
|
306 |
||
307 |
ZIP_Lock(zip); |
|
308 |
len = ZIP_Read(zip, jlong_to_ptr(zentry), pos, buf, len); |
|
309 |
msg = zip->msg; |
|
310 |
ZIP_Unlock(zip); |
|
311 |
if (len != -1) { |
|
312 |
(*env)->SetByteArrayRegion(env, bytes, off, len, buf); |
|
313 |
} |
|
314 |
||
315 |
if (len == -1) { |
|
316 |
if (msg != 0) { |
|
317 |
ThrowZipException(env, msg); |
|
318 |
} else { |
|
319 |
char errmsg[128]; |
|
320 |
sprintf(errmsg, "errno: %d, error: %s\n", |
|
321 |
errno, "Error reading ZIP file"); |
|
322 |
JNU_ThrowIOExceptionWithLastError(env, errmsg); |
|
323 |
} |
|
324 |
} |
|
325 |
||
326 |
return len; |
|
327 |
} |
|
328 |
||
329 |
/* |
|
330 |
* Returns an array of strings representing the names of all entries |
|
331 |
* that begin with "META-INF/" (case ignored). This native method is |
|
332 |
* used in JarFile as an optimization when looking up manifest and |
|
333 |
* signature file entries. Returns null if no entries were found. |
|
334 |
*/ |
|
335 |
JNIEXPORT jobjectArray JNICALL |
|
336 |
Java_java_util_jar_JarFile_getMetaInfEntryNames(JNIEnv *env, jobject obj) |
|
337 |
{ |
|
338 |
jlong zfile = (*env)->GetLongField(env, obj, jzfileID); |
|
339 |
jzfile *zip; |
|
340 |
int i, count; |
|
341 |
jobjectArray result = 0; |
|
342 |
||
343 |
if (zfile == 0) { |
|
344 |
JNU_ThrowByName(env, |
|
345 |
"java/lang/IllegalStateException", "zip file closed"); |
|
346 |
return NULL; |
|
347 |
} |
|
348 |
zip = jlong_to_ptr(zfile); |
|
349 |
||
350 |
/* count the number of valid ZIP metanames */ |
|
351 |
count = 0; |
|
352 |
if (zip->metanames != 0) { |
|
353 |
for (i = 0; i < zip->metacount; i++) { |
|
354 |
if (zip->metanames[i] != 0) { |
|
355 |
count++; |
|
356 |
} |
|
357 |
} |
|
358 |
} |
|
359 |
||
360 |
/* If some names were found then build array of java strings */ |
|
361 |
if (count > 0) { |
|
362 |
jclass cls = (*env)->FindClass(env, "java/lang/String"); |
|
363 |
result = (*env)->NewObjectArray(env, count, cls, 0); |
|
364 |
if (result != 0) { |
|
365 |
for (i = 0; i < count; i++) { |
|
366 |
jstring str = (*env)->NewStringUTF(env, zip->metanames[i]); |
|
367 |
if (str == 0) { |
|
368 |
break; |
|
369 |
} |
|
370 |
(*env)->SetObjectArrayElement(env, result, i, str); |
|
371 |
(*env)->DeleteLocalRef(env, str); |
|
372 |
} |
|
373 |
} |
|
374 |
} |
|
375 |
return result; |
|
376 |
} |
|
377 |
||
378 |
JNIEXPORT jstring JNICALL |
|
379 |
Java_java_util_zip_ZipFile_getZipMessage(JNIEnv *env, jclass cls, jlong zfile) |
|
380 |
{ |
|
381 |
jzfile *zip = jlong_to_ptr(zfile); |
|
382 |
char *msg = zip->msg; |
|
383 |
if (msg == NULL) { |
|
384 |
return NULL; |
|
385 |
} |
|
386 |
return JNU_NewStringPlatform(env, msg); |
|
387 |
} |