author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Sun, 16 Dec 2012 21:04:02 +0100 | |
branch | directory_structure_refactoring |
changeset 1899 | 800c0f76adce |
parent 1818 | 2e5ed72e7dfd |
child 1864 | 60a8dc26c8c6 |
permissions | -rw-r--r-- |
952 | 1 |
" |
2 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
|
1152 | 3 |
|
1155 | 4 |
New code and modifications done at SWING Research Group [1]: |
1152 | 5 |
|
952 | 6 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko |
7 |
SWING Research Group, Czech Technical University in Prague |
|
8 |
||
9 |
This software is furnished under a license and may be used |
|
10 |
only in accordance with the terms of that license and with the |
|
11 |
inclusion of the above copyright notice. This software may not |
|
12 |
be provided or otherwise made available to, or used by, any |
|
13 |
other person. No title to or ownership of the software is |
|
14 |
hereby transferred. |
|
15 |
||
1155 | 16 |
[1] Code written at SWING Research Group contains a signature |
17 |
of one of the above copright owners. For exact set of such code, |
|
18 |
see the differences between this version and version stx:libjava |
|
1152 | 19 |
as of 1.9.2010 |
952 | 20 |
" |
21 |
"{ Package: 'stx:libjava' }" |
|
22 |
||
23 |
Object subclass:#JavaZipSupport |
|
24 |
instanceVariableNames:'' |
|
25 |
classVariableNames:'' |
|
26 |
poolDictionaries:'' |
|
1536 | 27 |
category:'Languages-Java-Support-Native' |
28 |
! |
|
29 |
||
30 |
Object subclass:#Deflater |
|
31 |
instanceVariableNames:'vm z_stream' |
|
32 |
classVariableNames:'' |
|
33 |
poolDictionaries:'' |
|
34 |
privateIn:JavaZipSupport |
|
952 | 35 |
! |
36 |
||
37 |
Object subclass:#Inflater |
|
38 |
instanceVariableNames:'vm z_stream' |
|
39 |
classVariableNames:'' |
|
40 |
poolDictionaries:'' |
|
41 |
privateIn:JavaZipSupport |
|
42 |
! |
|
43 |
||
44 |
!JavaZipSupport primitiveDefinitions! |
|
45 |
%{ |
|
46 |
||
47 |
#include <stdio.h> |
|
48 |
#include <stdlib.h> |
|
49 |
#include <errno.h> |
|
50 |
#include <string.h> |
|
51 |
#include "zlib.h" |
|
52 |
||
53 |
#define MIN2(x, y) ((x) < (y) ? (x) : (y)) |
|
54 |
||
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
55 |
#define DEF_MEM_LEVEL 8 |
952 | 56 |
#define __zStreamVal(x) ((z_stream *)(__ExternalBytesInstPtr(x)->e_address)) |
57 |
||
58 |
%} |
|
59 |
! ! |
|
60 |
||
61 |
!JavaZipSupport class methodsFor:'documentation'! |
|
62 |
||
63 |
copyright |
|
64 |
" |
|
65 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
|
1152 | 66 |
|
1155 | 67 |
New code and modifications done at SWING Research Group [1]: |
1152 | 68 |
|
952 | 69 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko |
70 |
SWING Research Group, Czech Technical University in Prague |
|
71 |
||
72 |
This software is furnished under a license and may be used |
|
73 |
only in accordance with the terms of that license and with the |
|
74 |
inclusion of the above copyright notice. This software may not |
|
75 |
be provided or otherwise made available to, or used by, any |
|
76 |
other person. No title to or ownership of the software is |
|
77 |
hereby transferred. |
|
78 |
||
1155 | 79 |
[1] Code written at SWING Research Group contains a signature |
80 |
of one of the above copright owners. For exact set of such code, |
|
81 |
see the differences between this version and version stx:libjava |
|
1152 | 82 |
as of 1.9.2010 |
952 | 83 |
|
84 |
" |
|
85 |
! ! |
|
86 |
||
87 |
!JavaZipSupport class methodsFor:'instance creation'! |
|
88 |
||
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
89 |
deflaterFor: vm |
952 | 90 |
|
1536 | 91 |
^Deflater new vm: vm |
952 | 92 |
|
93 |
"Created: / 30-08-2011 / 09:05:04 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
94 |
|
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
95 |
! |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
96 |
|
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
97 |
inflaterFor: vm |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
98 |
|
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
99 |
^Inflater new vm: vm |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
100 |
|
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
101 |
"Created: / 30-08-2011 / 09:05:04 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
102 |
|
952 | 103 |
! ! |
104 |
||
1539 | 105 |
!JavaZipSupport::Deflater methodsFor:'* As yet uncategorized *'! |
106 |
||
107 |
> aSmallInteger |
|
108 |
^(z_stream address ? 0) > aSmallInteger |
|
109 |
||
110 |
"Created: / 20-07-2012 / 22:21:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
111 |
! ! |
|
112 |
||
1536 | 113 |
!JavaZipSupport::Deflater methodsFor:'accessing'! |
114 |
||
115 |
vm: javaVM |
|
116 |
||
117 |
vm := javaVM. |
|
118 |
||
119 |
"Created: / 30-08-2011 / 09:05:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
120 |
! ! |
|
121 |
||
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
122 |
!JavaZipSupport::Deflater methodsFor:'deflater methods'! |
1536 | 123 |
|
124 |
adler |
|
125 |
||
126 |
%{ |
|
127 |
RETURN ( __MKEXTERNALADDRESS ( __zStreamVal(__INST(z_stream))->adler ) ); |
|
128 |
%} |
|
129 |
||
130 |
" |
|
131 |
OpenJDK 7 Implementation: |
|
132 |
||
133 |
JNIEXPORT jint JNICALL |
|
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
134 |
Java_java_util_zip_Deflater_getAdler(JNIEnv *env, jclass cls, jlong addr) |
1536 | 135 |
{ |
136 |
return ((z_stream *)jlong_to_ptr(addr))->adler; |
|
137 |
} |
|
138 |
" |
|
139 |
||
140 |
"Created: / 31-08-2011 / 09:30:06 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
141 |
! |
|
142 |
||
143 |
bytesRead |
|
144 |
||
145 |
%{ |
|
146 |
RETURN ( __MKSMALLINT( __zStreamVal(__INST(z_stream))->total_in)); |
|
147 |
%} |
|
148 |
||
149 |
||
150 |
" |
|
151 |
OpenJDK 7 Implementation: |
|
152 |
||
153 |
JNIEXPORT jlong JNICALL |
|
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
154 |
Java_java_util_zip_Deflater_getBytesRead(JNIEnv *env, jclass cls, jlong addr) |
1536 | 155 |
{ |
156 |
return ((z_stream *)jlong_to_ptr(addr))->total_in; |
|
157 |
} |
|
158 |
" |
|
159 |
||
160 |
"Created: / 31-08-2011 / 09:30:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
161 |
! |
|
162 |
||
163 |
bytesWritten |
|
164 |
||
165 |
%{ |
|
166 |
RETURN ( __MKSMALLINT( __zStreamVal(__INST(z_stream))->total_out)); |
|
167 |
%} |
|
168 |
||
169 |
||
170 |
" |
|
171 |
OpenJDK 7 Implementation: |
|
172 |
||
173 |
JNIEXPORT jlong JNICALL |
|
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
174 |
Java_java_util_zip_Deflater_getBytesWritten(JNIEnv *env, jclass cls, jlong addr) |
1536 | 175 |
{ |
176 |
return ((z_stream *)jlong_to_ptr(addr))->total_out; |
|
177 |
} |
|
178 |
" |
|
179 |
||
180 |
"Created: / 31-08-2011 / 09:30:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
181 |
! |
|
182 |
||
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
183 |
deflate:"byte[]" out_buf offset: "int" out_off length: "int" out_len flush: flush deflater: deflater |
1536 | 184 |
|
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
185 |
| in_buf in_off in_len setParams level strategy finish finished ret errorType errorMsg| |
1536 | 186 |
in_buf := deflater instVarNamed:#buf. |
187 |
in_off := deflater instVarNamed:#off. |
|
188 |
in_len := deflater instVarNamed:#len. |
|
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
189 |
setParams := deflater instVarNamed:#setParams. |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
190 |
level := deflater instVarNamed:#level. |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
191 |
strategy := deflater instVarNamed:#strategy. |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
192 |
finish := deflater instVarNamed:#finish. |
1536 | 193 |
%{ |
194 |
#define strm (__zStreamVal(__INST(z_stream))) |
|
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
195 |
int code; |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
196 |
int consumed; |
1536 | 197 |
|
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
198 |
strm->next_in = (Bytef *)(__ByteArrayInstPtr(in_buf)->ba_element+__intVal(in_off)); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
199 |
strm->next_out = (Bytef *)(__ByteArrayInstPtr(out_buf)->ba_element+__intVal(out_off)); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
200 |
strm->avail_in = __intVal(in_len); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
201 |
strm->avail_out = __intVal(out_len); |
1536 | 202 |
|
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
203 |
if (__intVal(setParams)) { |
1543 | 204 |
code = deflateParams(strm, __intVal(level), __intVal(strategy)); |
1536 | 205 |
switch (code) { |
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
206 |
case Z_OK: |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
207 |
setParams = __intVal(0); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
208 |
consumed = __intVal(in_len) - strm->avail_in; |
1536 | 209 |
|
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
210 |
in_off = __MKSMALLINT(_intVal(in_off) + consumed); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
211 |
in_len = __MKSMALLINT(_intVal(in_len) - consumed); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
212 |
ret = __MKSMALLINT(__intVal(out_len) - strm->avail_out); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
213 |
break; |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
214 |
case Z_BUF_ERROR: |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
215 |
setParams = __intVal(0); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
216 |
ret = __MKSMALLINT(0); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
217 |
break; |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
218 |
default: |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
219 |
errorMsg = __MKSTRING(__zStreamVal(__INST(z_stream))->msg); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
220 |
errorType = @symbol(InternalError); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
221 |
break; |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
222 |
} |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
223 |
} else { |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
224 |
code = deflate(strm, __intVal(finish) ? Z_FINISH : __intVal(flush)); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
225 |
switch (code) { |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
226 |
case Z_STREAM_END: |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
227 |
finished = __MKSMALLINT(1); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
228 |
/* fall through */ |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
229 |
case Z_OK: |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
230 |
consumed = __intVal(in_len) - strm->avail_in; |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
231 |
in_off = __MKSMALLINT(_intVal(in_off) + consumed); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
232 |
in_len = __MKSMALLINT(_intVal(in_len) - consumed); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
233 |
ret = __MKSMALLINT(__intVal(out_len) - strm->avail_in); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
234 |
break; |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
235 |
case Z_BUF_ERROR: |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
236 |
ret = __MKSMALLINT(0); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
237 |
break; |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
238 |
default: |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
239 |
errorMsg = __MKSTRING(__zStreamVal(__INST(z_stream))->msg); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
240 |
errorType = @symbol(InternalError); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
241 |
break; |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
242 |
} |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
243 |
} |
1536 | 244 |
#undef strm |
245 |
%}. |
|
246 |
errorType == #OutOfMemoryError ifTrue:[ |
|
247 |
vm throwOutOfMemoryError. |
|
248 |
^0. |
|
249 |
]. |
|
250 |
errorType == #InternalError ifTrue:[ |
|
251 |
vm internalError: errorMsg. |
|
252 |
^0. |
|
253 |
]. |
|
254 |
||
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
255 |
deflater instVarNamed:#off put: in_off. |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
256 |
deflater instVarNamed:#len put: in_len. |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
257 |
deflater instVarNamed:#finished put: finished. |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
258 |
deflater instVarNamed:#setParams put: setParams. |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
259 |
|
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
260 |
|
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
261 |
^ret |
1536 | 262 |
|
263 |
" |
|
264 |
OpenJDK 7 Implementation |
|
265 |
||
266 |
JNIEXPORT jint JNICALL |
|
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
267 |
Java_java_util_zip_Deflater_deflateBytes(JNIEnv *env, jobject this, jlong addr, |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
268 |
jarray b, jint off, jint len, jint flush) |
1536 | 269 |
{ |
270 |
z_stream *strm = jlong_to_ptr(addr); |
|
271 |
||
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
272 |
jarray this_buf = (*env)->GetObjectField(env, this, bufID); |
1536 | 273 |
jint this_off = (*env)->GetIntField(env, this, offID); |
274 |
jint this_len = (*env)->GetIntField(env, this, lenID); |
|
275 |
jbyte *in_buf; |
|
276 |
jbyte *out_buf; |
|
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
277 |
int res; |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
278 |
if ((*env)->GetBooleanField(env, this, setParamsID)) { |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
279 |
int level = (*env)->GetIntField(env, this, levelID); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
280 |
int strategy = (*env)->GetIntField(env, this, strategyID); |
1536 | 281 |
|
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
282 |
in_buf = (jbyte *) malloc(this_len); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
283 |
if (in_buf == 0) { |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
284 |
JNU_ThrowOutOfMemoryError(env, 0); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
285 |
return 0; |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
286 |
} |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
287 |
(*env)->GetByteArrayRegion(env, this_buf, this_off, this_len, in_buf); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
288 |
out_buf = (jbyte *) malloc(len); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
289 |
if (out_buf == 0) { |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
290 |
free(in_buf); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
291 |
JNU_ThrowOutOfMemoryError(env, 0); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
292 |
return 0; |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
293 |
} |
1536 | 294 |
|
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
295 |
strm->next_in = (Bytef *) in_buf; |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
296 |
strm->next_out = (Bytef *) out_buf; |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
297 |
strm->avail_in = this_len; |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
298 |
strm->avail_out = len; |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
299 |
res = deflateParams(strm, level, strategy); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
300 |
|
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
301 |
if (res == Z_OK) { |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
302 |
(*env)->SetByteArrayRegion(env, b, off, len - strm->avail_out, out_buf); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
303 |
} |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
304 |
free(out_buf); |
1536 | 305 |
free(in_buf); |
306 |
||
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
307 |
switch (res) { |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
308 |
case Z_OK: |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
309 |
(*env)->SetBooleanField(env, this, setParamsID, JNI_FALSE); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
310 |
this_off += this_len - strm->avail_in; |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
311 |
(*env)->SetIntField(env, this, offID, this_off); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
312 |
(*env)->SetIntField(env, this, lenID, strm->avail_in); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
313 |
return len - strm->avail_out; |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
314 |
case Z_BUF_ERROR: |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
315 |
(*env)->SetBooleanField(env, this, setParamsID, JNI_FALSE); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
316 |
return 0; |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
317 |
default: |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
318 |
JNU_ThrowInternalError(env, strm->msg); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
319 |
return 0; |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
320 |
} |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
321 |
} else { |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
322 |
jboolean finish = (*env)->GetBooleanField(env, this, finishID); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
323 |
in_buf = (jbyte *) malloc(this_len); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
324 |
if (in_buf == 0) { |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
325 |
JNU_ThrowOutOfMemoryError(env, 0); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
326 |
return 0; |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
327 |
} |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
328 |
(*env)->GetByteArrayRegion(env, this_buf, this_off, this_len, in_buf); |
1536 | 329 |
|
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
330 |
out_buf = (jbyte *) malloc(len); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
331 |
if (out_buf == 0) { |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
332 |
free(in_buf); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
333 |
JNU_ThrowOutOfMemoryError(env, 0); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
334 |
return 0; |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
335 |
} |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
336 |
|
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
337 |
strm->next_in = (Bytef *) in_buf; |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
338 |
strm->next_out = (Bytef *) out_buf; |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
339 |
strm->avail_in = this_len; |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
340 |
strm->avail_out = len; |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
341 |
res = deflate(strm, finish ? Z_FINISH : flush); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
342 |
|
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
343 |
if (res == Z_STREAM_END || res == Z_OK) { |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
344 |
(*env)->SetByteArrayRegion(env, b, off, len - strm->avail_out, out_buf); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
345 |
} |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
346 |
free(out_buf); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
347 |
free(in_buf); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
348 |
|
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
349 |
switch (res) { |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
350 |
case Z_STREAM_END: |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
351 |
(*env)->SetBooleanField(env, this, finishedID, JNI_TRUE); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
352 |
/* fall through */ |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
353 |
case Z_OK: |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
354 |
this_off += this_len - strm->avail_in; |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
355 |
(*env)->SetIntField(env, this, offID, this_off); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
356 |
(*env)->SetIntField(env, this, lenID, strm->avail_in); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
357 |
return len - strm->avail_out; |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
358 |
case Z_BUF_ERROR: |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
359 |
return 0; |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
360 |
default: |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
361 |
JNU_ThrowInternalError(env, strm->msg); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
362 |
return 0; |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
363 |
} |
1536 | 364 |
} |
365 |
} |
|
366 |
" |
|
367 |
||
1538
baa8e06aac40
- finalization hack for ZipFile, Inflater and Deflater
vranyj1
parents:
1537
diff
changeset
|
368 |
"Created: / 20-07-2012 / 17:55:04 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1536 | 369 |
! |
370 |
||
371 |
end |
|
372 |
||
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
373 |
| ok | |
1536 | 374 |
|
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
375 |
ok := true. |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
376 |
%{ |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
377 |
if (deflateEnd(__zStreamVal(__INST(z_stream))) == Z_STREAM_ERROR) { |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
378 |
ok = false; |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
379 |
} |
1536 | 380 |
%}. |
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
381 |
z_stream free. |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
382 |
ok ifFalse:[ |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
383 |
vm internalError: 'deflateEnd() failed!!'. |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
384 |
]. |
1536 | 385 |
|
386 |
" |
|
387 |
OpenJDK 7 Implementation: |
|
388 |
||
389 |
JNIEXPORT void JNICALL |
|
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
390 |
Java_java_util_zip_Deflater_end(JNIEnv *env, jclass cls, jlong addr) |
1536 | 391 |
{ |
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
392 |
if (deflateEnd((z_stream *)jlong_to_ptr(addr)) == Z_STREAM_ERROR) { |
1536 | 393 |
JNU_ThrowInternalError(env, 0); |
394 |
} else { |
|
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
395 |
free((z_stream *)jlong_to_ptr(addr)); |
1536 | 396 |
} |
397 |
} |
|
398 |
" |
|
399 |
||
400 |
"Created: / 30-08-2011 / 20:50:23 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
401 |
! |
|
402 |
||
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
403 |
init: strategy level: level nowrap: nowrap |
1536 | 404 |
|
405 |
| z_stream_size errorType errorMsg | |
|
406 |
||
407 |
%{ z_stream_size = __MKSMALLINT(sizeof(z_stream)); %}. |
|
408 |
z_stream := ExternalBytes unprotectedNew: z_stream_size. |
|
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
409 |
z_stream address == 0 ifTrue:[ |
1538
baa8e06aac40
- finalization hack for ZipFile, Inflater and Deflater
vranyj1
parents:
1537
diff
changeset
|
410 |
vm throwOutOfMemoryError |
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
411 |
]. |
1536 | 412 |
|
413 |
%{ |
|
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
414 |
switch (deflateInit2(__zStreamVal(__INST(z_stream)), |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
415 |
__intVal(level), |
1538
baa8e06aac40
- finalization hack for ZipFile, Inflater and Deflater
vranyj1
parents:
1537
diff
changeset
|
416 |
Z_DEFLATED, |
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
417 |
(nowrap ? -MAX_WBITS : MAX_WBITS), |
1538
baa8e06aac40
- finalization hack for ZipFile, Inflater and Deflater
vranyj1
parents:
1537
diff
changeset
|
418 |
DEF_MEM_LEVEL, |
baa8e06aac40
- finalization hack for ZipFile, Inflater and Deflater
vranyj1
parents:
1537
diff
changeset
|
419 |
__intVal(strategy) )) { |
1536 | 420 |
case Z_OK: |
1538
baa8e06aac40
- finalization hack for ZipFile, Inflater and Deflater
vranyj1
parents:
1537
diff
changeset
|
421 |
break; |
1536 | 422 |
case Z_MEM_ERROR: |
423 |
errorType = @symbol(OutOfMemoryError); |
|
424 |
break; |
|
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
425 |
case Z_STREAM_ERROR: |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
426 |
errorType = @symbol(StreamError); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
427 |
break; |
1536 | 428 |
default: |
429 |
errorMsg = __MKSTRING(__zStreamVal(__INST(z_stream))->msg); |
|
430 |
errorType = @symbol(InternalError); |
|
431 |
break; |
|
432 |
} |
|
433 |
%}. |
|
434 |
||
1538
baa8e06aac40
- finalization hack for ZipFile, Inflater and Deflater
vranyj1
parents:
1537
diff
changeset
|
435 |
errorType isNil ifTrue:[ |
1746
475fce490520
- Use ZipInflaters array (no direct referenceto JavaZipSupport::Inflater/Deflater in Java objects)
vranyj1
parents:
1546
diff
changeset
|
436 |
"/ self registerForFinalization. |
1539 | 437 |
^self |
1538
baa8e06aac40
- finalization hack for ZipFile, Inflater and Deflater
vranyj1
parents:
1537
diff
changeset
|
438 |
]. |
baa8e06aac40
- finalization hack for ZipFile, Inflater and Deflater
vranyj1
parents:
1537
diff
changeset
|
439 |
|
1536 | 440 |
z_stream free. |
441 |
errorType == #OutOfMemoryError ifTrue:[ |
|
442 |
vm throwOutOfMemoryError. |
|
443 |
^self. |
|
444 |
]. |
|
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
445 |
errorType == #StreamError ifTrue:[ |
1539 | 446 |
vm throwIllegalArgumentException: |
1538
baa8e06aac40
- finalization hack for ZipFile, Inflater and Deflater
vranyj1
parents:
1537
diff
changeset
|
447 |
'Z_STREAM_ERROR returned from inflateInit2'. |
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
448 |
^self. |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
449 |
]. |
1536 | 450 |
errorType == #InternalError ifTrue:[ |
451 |
vm internalError: errorMsg. |
|
452 |
^self. |
|
453 |
]. |
|
1538
baa8e06aac40
- finalization hack for ZipFile, Inflater and Deflater
vranyj1
parents:
1537
diff
changeset
|
454 |
|
baa8e06aac40
- finalization hack for ZipFile, Inflater and Deflater
vranyj1
parents:
1537
diff
changeset
|
455 |
vm internalError: 'Unknown error: ', errorMsg asString. |
1536 | 456 |
|
457 |
||
458 |
||
459 |
" |
|
460 |
OpenJDK 7 Implementation: |
|
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
461 |
|
1536 | 462 |
JNIEXPORT jlong JNICALL |
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
463 |
Java_java_util_zip_Deflater_init(JNIEnv *env, jclass cls, jint level, |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
464 |
jint strategy, jboolean nowrap) |
1536 | 465 |
{ |
466 |
z_stream *strm = calloc(1, sizeof(z_stream)); |
|
467 |
||
468 |
if (strm == 0) { |
|
469 |
JNU_ThrowOutOfMemoryError(env, 0); |
|
470 |
return jlong_zero; |
|
471 |
} else { |
|
472 |
char *msg; |
|
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
473 |
switch (deflateInit2(strm, level, Z_DEFLATED, |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
474 |
nowrap ? -MAX_WBITS : MAX_WBITS, |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
475 |
DEF_MEM_LEVEL, strategy)) { |
1536 | 476 |
case Z_OK: |
477 |
return ptr_to_jlong(strm); |
|
478 |
case Z_MEM_ERROR: |
|
479 |
free(strm); |
|
480 |
JNU_ThrowOutOfMemoryError(env, 0); |
|
481 |
return jlong_zero; |
|
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
482 |
case Z_STREAM_ERROR: |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
483 |
free(strm); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
484 |
JNU_ThrowIllegalArgumentException(env, 0); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
485 |
return jlong_zero; |
1536 | 486 |
default: |
487 |
msg = strm->msg; |
|
488 |
free(strm); |
|
489 |
JNU_ThrowInternalError(env, msg); |
|
490 |
return jlong_zero; |
|
491 |
} |
|
492 |
} |
|
493 |
" |
|
494 |
||
495 |
"Created: / 29-08-2011 / 17:22:04 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1746
475fce490520
- Use ZipInflaters array (no direct referenceto JavaZipSupport::Inflater/Deflater in Java objects)
vranyj1
parents:
1546
diff
changeset
|
496 |
"Modified: / 25-10-2012 / 20:27:48 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1536 | 497 |
! |
498 |
||
499 |
reset |
|
500 |
||
501 |
%{ |
|
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
502 |
if (deflateReset(__zStreamVal(__INST(z_stream))) == Z_OK) { |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
503 |
RETURN ( self ); |
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
504 |
} |
1536 | 505 |
%}. |
506 |
||
507 |
vm internalError: 'Cannot reset inflater'. |
|
508 |
||
509 |
" |
|
510 |
OpenJDK 7 Implementation: |
|
511 |
||
512 |
JNIEXPORT void JNICALL |
|
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
513 |
Java_java_util_zip_Deflater_reset(JNIEnv *env, jclass cls, jlong addr) |
1536 | 514 |
{ |
1537
0072327ccc71
- JavaVM: some new natives for zip, mainly Deflater. No ZipFile finalization hack yet.
vranyj1
parents:
1536
diff
changeset
|
515 |
if (deflateReset((z_stream *)jlong_to_ptr(addr)) !!= Z_OK) { |
1536 | 516 |
JNU_ThrowInternalError(env, 0); |
517 |
} |
|
518 |
} |
|
519 |
" |
|
520 |
||
521 |
"Created: / 30-08-2011 / 12:45:31 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
522 |
! ! |
|
523 |
||
1538
baa8e06aac40
- finalization hack for ZipFile, Inflater and Deflater
vranyj1
parents:
1537
diff
changeset
|
524 |
!JavaZipSupport::Deflater methodsFor:'initialization & release'! |
baa8e06aac40
- finalization hack for ZipFile, Inflater and Deflater
vranyj1
parents:
1537
diff
changeset
|
525 |
|
baa8e06aac40
- finalization hack for ZipFile, Inflater and Deflater
vranyj1
parents:
1537
diff
changeset
|
526 |
finalize |
baa8e06aac40
- finalization hack for ZipFile, Inflater and Deflater
vranyj1
parents:
1537
diff
changeset
|
527 |
|
1539 | 528 |
(z_stream notNil and:[z_stream isValid]) ifTrue:[self end]. |
1538
baa8e06aac40
- finalization hack for ZipFile, Inflater and Deflater
vranyj1
parents:
1537
diff
changeset
|
529 |
|
baa8e06aac40
- finalization hack for ZipFile, Inflater and Deflater
vranyj1
parents:
1537
diff
changeset
|
530 |
"Created: / 20-07-2012 / 21:50:11 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
baa8e06aac40
- finalization hack for ZipFile, Inflater and Deflater
vranyj1
parents:
1537
diff
changeset
|
531 |
! ! |
baa8e06aac40
- finalization hack for ZipFile, Inflater and Deflater
vranyj1
parents:
1537
diff
changeset
|
532 |
|
1546 | 533 |
!JavaZipSupport::Inflater methodsFor:'* As yet uncategorized *'! |
534 |
||
535 |
> aSmallInteger |
|
536 |
^z_stream address > 0 |
|
537 |
||
538 |
"Created: / 23-07-2012 / 21:06:24 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
539 |
! ! |
|
540 |
||
952 | 541 |
!JavaZipSupport::Inflater methodsFor:'accessing'! |
542 |
||
543 |
vm: javaVM |
|
544 |
||
545 |
vm := javaVM. |
|
546 |
||
547 |
"Created: / 30-08-2011 / 09:05:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
548 |
! ! |
|
549 |
||
550 |
!JavaZipSupport::Inflater methodsFor:'inflater methods'! |
|
551 |
||
552 |
adler |
|
553 |
||
554 |
%{ |
|
555 |
RETURN ( __MKEXTERNALADDRESS ( __zStreamVal(__INST(z_stream))->adler ) ); |
|
556 |
%} |
|
557 |
||
558 |
" |
|
559 |
OpenJDK 7 Implementation: |
|
560 |
||
561 |
JNIEXPORT jint JNICALL |
|
562 |
Java_java_util_zip_Inflater_getAdler(JNIEnv *env, jclass cls, jlong addr) |
|
563 |
{ |
|
564 |
return ((z_stream *)jlong_to_ptr(addr))->adler; |
|
565 |
} |
|
566 |
" |
|
567 |
||
568 |
"Created: / 31-08-2011 / 09:30:06 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
569 |
! |
|
570 |
||
571 |
bytesRead |
|
572 |
||
573 |
%{ |
|
574 |
RETURN ( __MKSMALLINT( __zStreamVal(__INST(z_stream))->total_in)); |
|
575 |
%} |
|
576 |
||
577 |
||
578 |
" |
|
579 |
OpenJDK 7 Implementation: |
|
580 |
||
581 |
JNIEXPORT jlong JNICALL |
|
582 |
Java_java_util_zip_Inflater_getBytesRead(JNIEnv *env, jclass cls, jlong addr) |
|
583 |
{ |
|
584 |
return ((z_stream *)jlong_to_ptr(addr))->total_in; |
|
585 |
} |
|
586 |
" |
|
587 |
||
588 |
"Created: / 31-08-2011 / 09:30:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
589 |
! |
|
590 |
||
591 |
bytesWritten |
|
592 |
||
593 |
%{ |
|
594 |
RETURN ( __MKSMALLINT( __zStreamVal(__INST(z_stream))->total_out)); |
|
595 |
%} |
|
596 |
||
597 |
||
598 |
" |
|
599 |
OpenJDK 7 Implementation: |
|
600 |
||
601 |
JNIEXPORT jlong JNICALL |
|
602 |
Java_java_util_zip_Inflater_getBytesWritten(JNIEnv *env, jclass cls, jlong addr) |
|
603 |
{ |
|
604 |
return ((z_stream *)jlong_to_ptr(addr))->total_out; |
|
605 |
} |
|
606 |
" |
|
607 |
||
608 |
"Created: / 31-08-2011 / 09:30:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
609 |
! |
|
610 |
||
611 |
end |
|
612 |
||
613 |
| ok | |
|
614 |
||
615 |
ok := true. |
|
616 |
||
617 |
%{ |
|
618 |
if (inflateEnd(__zStreamVal(__INST(z_stream))) == Z_STREAM_ERROR) { |
|
619 |
ok = false; |
|
620 |
} |
|
621 |
%}. |
|
622 |
z_stream free. |
|
623 |
ok ifFalse:[ |
|
624 |
vm internalError: 'Cannot call inflateEnd()'. |
|
625 |
]. |
|
626 |
||
627 |
" |
|
628 |
OpenJDK 7 Implementation: |
|
629 |
||
630 |
JNIEXPORT void JNICALL |
|
631 |
Java_java_util_zip_Inflater_end(JNIEnv *env, jclass cls, jlong addr) |
|
632 |
{ |
|
633 |
if (inflateEnd(jlong_to_ptr(addr)) == Z_STREAM_ERROR) { |
|
634 |
JNU_ThrowInternalError(env, 0); |
|
635 |
} else { |
|
636 |
free(jlong_to_ptr(addr)); |
|
637 |
} |
|
638 |
} |
|
639 |
||
640 |
" |
|
641 |
||
642 |
"Created: / 30-08-2011 / 20:50:23 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
643 |
! |
|
644 |
||
645 |
inflate:"byte[]" out_buf offset: "int" out_off length: "int" out_len inflater: jinflater |
|
646 |
||
647 |
| in_buf in_off in_len finished needDict errorType errorMsg ret | |
|
648 |
in_buf := jinflater instVarNamed:#buf. |
|
649 |
in_off := jinflater instVarNamed:#off. |
|
650 |
in_len := jinflater instVarNamed:#len. |
|
651 |
||
652 |
finished := needDict := 0. |
|
653 |
||
654 |
%{ |
|
655 |
#define strm (__zStreamVal(__INST(z_stream))) |
|
963 | 656 |
int code, consumed; |
657 |
||
952 | 658 |
strm->next_in = (Bytef *) (__ByteArrayInstPtr(in_buf)->ba_element + __intVal(in_off)); |
659 |
strm->next_out = (Bytef *) (__ByteArrayInstPtr(out_buf)->ba_element + __intVal(out_off)); |
|
660 |
strm->avail_in = __intVal(in_len); |
|
661 |
strm->avail_out = __intVal(out_len); |
|
662 |
||
963 | 663 |
|
952 | 664 |
code = inflate(strm, Z_PARTIAL_FLUSH); |
665 |
||
666 |
switch (code) { |
|
667 |
case Z_STREAM_END: |
|
668 |
finished = __MKSMALLINT(1); |
|
669 |
/* fall through */ |
|
670 |
case Z_OK: |
|
671 |
consumed = __intVal(in_len) - strm->avail_in; |
|
672 |
in_off = __MKSMALLINT(_intVal(in_off) + consumed); |
|
673 |
in_len = __MKSMALLINT(_intVal(in_len) - consumed); |
|
674 |
ret = __MKSMALLINT(__intVal(out_len) - strm->avail_out); |
|
675 |
break; |
|
676 |
case Z_NEED_DICT: |
|
677 |
needDict = __MKSMALLINT(1); |
|
678 |
/* Might have consumed some input here! */ |
|
679 |
consumed = __intVal(in_len) - strm->avail_in; |
|
680 |
in_off = __MKSMALLINT(_intVal(in_off) + consumed); |
|
681 |
in_len = __MKSMALLINT(_intVal(in_len) - consumed); |
|
682 |
ret = __MKSMALLINT(0); |
|
683 |
break; |
|
684 |
case Z_BUF_ERROR: |
|
685 |
ret = __MKSMALLINT(0); |
|
686 |
break; |
|
687 |
case Z_DATA_ERROR: |
|
688 |
errorMsg = __MKSTRING(__zStreamVal(__INST(z_stream))->msg); |
|
689 |
errorType = @symbol(DataFormatException); |
|
690 |
||
691 |
break; |
|
692 |
case Z_MEM_ERROR: |
|
693 |
errorType = @symbol(OutOfMemoryError); |
|
694 |
break; |
|
695 |
default: |
|
696 |
errorMsg = __MKSTRING(__zStreamVal(__INST(z_stream))->msg); |
|
697 |
errorType = @symbol(InternalError); |
|
698 |
break; |
|
699 |
} |
|
700 |
#undef strm |
|
701 |
%}. |
|
702 |
errorType == #DataFormatException ifTrue:[ |
|
703 |
vm throwDataFormatException: errorMsg. |
|
704 |
^0. |
|
705 |
]. |
|
706 |
errorType == #OutOfMemoryError ifTrue:[ |
|
707 |
vm throwOutOfMemoryError. |
|
708 |
^0. |
|
709 |
]. |
|
710 |
errorType == #InternalError ifTrue:[ |
|
711 |
vm internalError: errorMsg. |
|
712 |
^0. |
|
713 |
]. |
|
714 |
||
715 |
jinflater instVarNamed:#off put: in_off. |
|
716 |
jinflater instVarNamed:#len put: in_len. |
|
717 |
jinflater instVarNamed:#finished put: finished. |
|
718 |
jinflater instVarNamed:#needDict put: needDict. |
|
719 |
^ret |
|
720 |
||
721 |
" |
|
722 |
OpenJDK 7 Implementation |
|
723 |
||
724 |
JNIEXPORT jint JNICALL |
|
725 |
Java_java_util_zip_Inflater_inflateBytes(JNIEnv *env, jobject this, jlong addr, |
|
726 |
jarray b, jint off, jint len) |
|
727 |
{ |
|
728 |
z_stream *strm = jlong_to_ptr(addr); |
|
729 |
||
730 |
jarray this_buf = (jarray)(*env)->GetObjectField(env, this, bufID); |
|
731 |
jint this_off = (*env)->GetIntField(env, this, offID); |
|
732 |
jint this_len = (*env)->GetIntField(env, this, lenID); |
|
733 |
jbyte *in_buf; |
|
734 |
jbyte *out_buf; |
|
735 |
int ret; |
|
736 |
/* |
|
737 |
* Avoid excess copying. |
|
738 |
* zlib stream usually has a few bytes of overhead for header info |
|
739 |
* (depends on the underlying data) |
|
740 |
* |
|
741 |
* (a) 5 bytes per 16KB |
|
742 |
* (b) 6 bytes for entire stream |
|
743 |
* (c) 4 bytes for gzip header |
|
744 |
* (d) 2 bytes for crc |
|
745 |
* |
|
746 |
* Use 20 bytes as the 'safe cutoff' number. |
|
747 |
*/ |
|
748 |
jint in_len = MIN2(this_len, len + 20); |
|
749 |
jint consumed; |
|
750 |
||
751 |
in_buf = (jbyte *) malloc(in_len); |
|
752 |
if (in_buf == 0) { |
|
753 |
JNU_ThrowOutOfMemoryError(env, 0); |
|
754 |
return 0; |
|
755 |
} |
|
756 |
(*env)->GetByteArrayRegion(env, this_buf, this_off, in_len, in_buf); |
|
757 |
||
758 |
out_buf = (jbyte *) malloc(len); |
|
759 |
if (out_buf == 0) { |
|
760 |
free(in_buf); |
|
761 |
JNU_ThrowOutOfMemoryError(env, 0); |
|
762 |
return 0; |
|
763 |
} |
|
764 |
||
765 |
strm->next_in = (Bytef *) in_buf; |
|
766 |
strm->next_out = (Bytef *) out_buf; |
|
767 |
strm->avail_in = in_len; |
|
768 |
strm->avail_out = len; |
|
769 |
ret = inflate(strm, Z_PARTIAL_FLUSH); |
|
770 |
||
771 |
if (ret == Z_STREAM_END || ret == Z_OK) { |
|
772 |
(*env)->SetByteArrayRegion(env, b, off, len - strm->avail_out, out_buf); |
|
773 |
} |
|
774 |
free(out_buf); |
|
775 |
free(in_buf); |
|
776 |
||
777 |
switch (ret) { |
|
778 |
case Z_STREAM_END: |
|
779 |
(*env)->SetBooleanField(env, this, finishedID, JNI_TRUE); |
|
780 |
/* fall through */ |
|
781 |
case Z_OK: |
|
782 |
consumed = in_len - strm->avail_in; |
|
783 |
(*env)->SetIntField(env, this, offID, this_off + consumed); |
|
784 |
(*env)->SetIntField(env, this, lenID, this_len - consumed); |
|
785 |
return len - strm->avail_out; |
|
786 |
case Z_NEED_DICT: |
|
787 |
(*env)->SetBooleanField(env, this, needDictID, JNI_TRUE); |
|
788 |
/* Might have consumed some input here!! */ |
|
789 |
consumed = in_len - strm->avail_in; |
|
790 |
(*env)->SetIntField(env, this, offID, this_off + consumed); |
|
791 |
(*env)->SetIntField(env, this, lenID, this_len - consumed); |
|
792 |
return 0; |
|
793 |
case Z_BUF_ERROR: |
|
794 |
return 0; |
|
795 |
case Z_DATA_ERROR: |
|
796 |
ThrowDataFormatException(env, strm->msg); |
|
797 |
return 0; |
|
798 |
case Z_MEM_ERROR: |
|
799 |
JNU_ThrowOutOfMemoryError(env, 0); |
|
800 |
return 0; |
|
801 |
default: |
|
802 |
JNU_ThrowInternalError(env, strm->msg); |
|
803 |
return 0; |
|
804 |
} |
|
805 |
} |
|
806 |
||
807 |
" |
|
808 |
||
809 |
"Created: / 30-08-2011 / 09:31:19 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
810 |
! |
|
811 |
||
812 |
init: nowrap |
|
813 |
||
814 |
| z_stream_size errorType errorMsg | |
|
815 |
||
816 |
%{ z_stream_size = __MKSMALLINT(sizeof(z_stream)); %}. |
|
817 |
||
818 |
z_stream := ExternalBytes unprotectedNew: z_stream_size. |
|
819 |
||
820 |
||
821 |
%{ |
|
822 |
switch (inflateInit2(__zStreamVal(__INST(z_stream)), nowrap ? -MAX_WBITS : MAX_WBITS)) { |
|
823 |
case Z_OK: |
|
1538
baa8e06aac40
- finalization hack for ZipFile, Inflater and Deflater
vranyj1
parents:
1537
diff
changeset
|
824 |
break; |
952 | 825 |
case Z_MEM_ERROR: |
826 |
errorType = @symbol(OutOfMemoryError); |
|
827 |
break; |
|
828 |
default: |
|
829 |
errorMsg = __MKSTRING(__zStreamVal(__INST(z_stream))->msg); |
|
830 |
errorType = @symbol(InternalError); |
|
831 |
break; |
|
832 |
} |
|
833 |
%}. |
|
1538
baa8e06aac40
- finalization hack for ZipFile, Inflater and Deflater
vranyj1
parents:
1537
diff
changeset
|
834 |
errorType isNil ifTrue:[ |
1746
475fce490520
- Use ZipInflaters array (no direct referenceto JavaZipSupport::Inflater/Deflater in Java objects)
vranyj1
parents:
1546
diff
changeset
|
835 |
"/ self registerForFinalization. |
1539 | 836 |
^self |
1538
baa8e06aac40
- finalization hack for ZipFile, Inflater and Deflater
vranyj1
parents:
1537
diff
changeset
|
837 |
]. |
952 | 838 |
|
839 |
z_stream free. |
|
840 |
errorType == #OutOfMemoryError ifTrue:[ |
|
841 |
vm throwOutOfMemoryError. |
|
842 |
^self. |
|
843 |
]. |
|
844 |
errorType == #InternalError ifTrue:[ |
|
845 |
vm internalError: errorMsg. |
|
846 |
^self. |
|
847 |
]. |
|
848 |
||
849 |
||
850 |
||
851 |
" |
|
852 |
OpenJDK 7 Implementation: |
|
853 |
JNIEXPORT jlong JNICALL |
|
854 |
Java_java_util_zip_Inflater_init(JNIEnv *env, jclass cls, jboolean nowrap) |
|
855 |
{ |
|
856 |
z_stream *strm = calloc(1, sizeof(z_stream)); |
|
857 |
||
858 |
if (strm == 0) { |
|
859 |
JNU_ThrowOutOfMemoryError(env, 0); |
|
860 |
return jlong_zero; |
|
861 |
} else { |
|
862 |
char *msg; |
|
863 |
switch (inflateInit2(strm, nowrap ? -MAX_WBITS : MAX_WBITS)) { |
|
864 |
case Z_OK: |
|
865 |
return ptr_to_jlong(strm); |
|
866 |
case Z_MEM_ERROR: |
|
867 |
free(strm); |
|
868 |
JNU_ThrowOutOfMemoryError(env, 0); |
|
869 |
return jlong_zero; |
|
870 |
default: |
|
871 |
msg = strm->msg; |
|
872 |
free(strm); |
|
873 |
JNU_ThrowInternalError(env, msg); |
|
874 |
return jlong_zero; |
|
875 |
} |
|
876 |
} |
|
877 |
} |
|
878 |
||
879 |
" |
|
880 |
||
881 |
"Created: / 29-08-2011 / 17:22:04 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1746
475fce490520
- Use ZipInflaters array (no direct referenceto JavaZipSupport::Inflater/Deflater in Java objects)
vranyj1
parents:
1546
diff
changeset
|
882 |
"Modified: / 25-10-2012 / 20:28:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
952 | 883 |
! |
884 |
||
885 |
reset |
|
886 |
||
887 |
%{ |
|
888 |
if (inflateReset(__zStreamVal(__INST(z_stream))) == Z_OK) { |
|
889 |
RETURN ( self ); |
|
890 |
} |
|
891 |
%}. |
|
892 |
||
893 |
vm internalError: 'Cannot reset inflater'. |
|
894 |
||
895 |
" |
|
896 |
OpenJDK 7 Implementation: |
|
897 |
||
898 |
JNIEXPORT void JNICALL |
|
899 |
Java_java_util_zip_Inflater_reset(JNIEnv *env, jclass cls, jlong addr) |
|
900 |
{ |
|
901 |
if (inflateReset(jlong_to_ptr(addr)) !!= Z_OK) { |
|
902 |
JNU_ThrowInternalError(env, 0); |
|
903 |
} |
|
904 |
} |
|
905 |
||
906 |
" |
|
907 |
||
908 |
"Created: / 30-08-2011 / 12:45:31 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
909 |
! ! |
|
910 |
||
1538
baa8e06aac40
- finalization hack for ZipFile, Inflater and Deflater
vranyj1
parents:
1537
diff
changeset
|
911 |
!JavaZipSupport::Inflater methodsFor:'initialization & release'! |
baa8e06aac40
- finalization hack for ZipFile, Inflater and Deflater
vranyj1
parents:
1537
diff
changeset
|
912 |
|
baa8e06aac40
- finalization hack for ZipFile, Inflater and Deflater
vranyj1
parents:
1537
diff
changeset
|
913 |
finalize |
baa8e06aac40
- finalization hack for ZipFile, Inflater and Deflater
vranyj1
parents:
1537
diff
changeset
|
914 |
|
1539 | 915 |
(z_stream notNil and:[z_stream isValid]) ifTrue:[self end]. |
1538
baa8e06aac40
- finalization hack for ZipFile, Inflater and Deflater
vranyj1
parents:
1537
diff
changeset
|
916 |
|
baa8e06aac40
- finalization hack for ZipFile, Inflater and Deflater
vranyj1
parents:
1537
diff
changeset
|
917 |
"Created: / 20-07-2012 / 21:50:11 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
baa8e06aac40
- finalization hack for ZipFile, Inflater and Deflater
vranyj1
parents:
1537
diff
changeset
|
918 |
! ! |
baa8e06aac40
- finalization hack for ZipFile, Inflater and Deflater
vranyj1
parents:
1537
diff
changeset
|
919 |
|
952 | 920 |
!JavaZipSupport class methodsFor:'documentation'! |
921 |
||
922 |
version_SVN |
|
923 |
^ '$Id$' |
|
924 |
! ! |