Created
December 18, 2019 22:51
-
-
Save conorgriffin/c6df9162bd20815587d8e947f47c5a41 to your computer and use it in GitHub Desktop.
Native method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Java_java_util_zip_Deflater_init(JNIEnv *env, jclass cls, jint level, | |
jint strategy, jboolean nowrap) | |
{ | |
z_stream *strm = calloc(1, sizeof(z_stream)); | |
if (strm == 0) { | |
JNU_ThrowOutOfMemoryError(env, 0); | |
return jlong_zero; | |
} else { | |
char *msg; | |
switch (deflateInit2(strm, level, Z_DEFLATED, | |
nowrap ? -MAX_WBITS : MAX_WBITS, | |
DEF_MEM_LEVEL, strategy)) { | |
case Z_OK: | |
return ptr_to_jlong(strm); | |
case Z_MEM_ERROR: | |
free(strm); | |
JNU_ThrowOutOfMemoryError(env, 0); | |
return jlong_zero; | |
case Z_STREAM_ERROR: | |
free(strm); | |
JNU_ThrowIllegalArgumentException(env, 0); | |
return jlong_zero; | |
default: | |
msg = strm->msg; | |
free(strm); | |
JNU_ThrowInternalError(env, msg); | |
return jlong_zero; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment