< prev index next >

src/java.base/share/native/libzip/Inflater.c

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 85,96 **** return jlong_zero; } } } ! static void checkSetDictionaryResult(JNIEnv *env, jlong addr, int res) { switch (res) { case Z_OK: break; case Z_STREAM_ERROR: case Z_DATA_ERROR: --- 85,97 ---- return jlong_zero; } } } ! static void doSetDictionary(JNIEnv *env, jlong addr, jbyte *buf, jint len) { + int res = inflateSetDictionary(jlong_to_ptr(addr), (Bytef *) buf, len); switch (res) { case Z_OK: break; case Z_STREAM_ERROR: case Z_DATA_ERROR:
*** 104,155 **** JNIEXPORT void JNICALL Java_java_util_zip_Inflater_setDictionary(JNIEnv *env, jclass cls, jlong addr, jbyteArray b, jint off, jint len) { ! jint res; ! Bytef *buf = (*env)->GetPrimitiveArrayCritical(env, b, 0); if (buf == NULL) /* out of memory */ return; ! res = inflateSetDictionary(jlong_to_ptr(addr), buf + off, len); (*env)->ReleasePrimitiveArrayCritical(env, b, buf, 0); - checkSetDictionaryResult(env, addr, res); } JNIEXPORT void JNICALL Java_java_util_zip_Inflater_setDictionaryBuffer(JNIEnv *env, jclass cls, jlong addr, jlong bufferAddr, jint len) { ! jint res; ! Bytef *buf = jlong_to_ptr(bufferAddr); ! res = inflateSetDictionary(jlong_to_ptr(addr), buf, len); ! checkSetDictionaryResult(env, addr, res); } ! static jint doInflate(jlong addr, jbyte *input, jint inputLen, jbyte *output, jint outputLen) { - jint ret; z_stream *strm = jlong_to_ptr(addr); strm->next_in = (Bytef *) input; strm->next_out = (Bytef *) output; strm->avail_in = inputLen; strm->avail_out = outputLen; ret = inflate(strm, Z_PARTIAL_FLUSH); - return ret; - } - - static jlong checkInflateStatus(JNIEnv *env, jobject this, jlong addr, - jint inputLen, jint outputLen, jint ret ) - { - z_stream *strm = jlong_to_ptr(addr); - jint inputUsed = 0, outputUsed = 0; - int finished = 0; - int needDict = 0; switch (ret) { case Z_STREAM_END: finished = 1; /* fall through */ --- 105,145 ---- JNIEXPORT void JNICALL Java_java_util_zip_Inflater_setDictionary(JNIEnv *env, jclass cls, jlong addr, jbyteArray b, jint off, jint len) { ! jbyte *buf = (*env)->GetPrimitiveArrayCritical(env, b, 0); if (buf == NULL) /* out of memory */ return; ! doSetDictionary(env, addr, buf + off, len); (*env)->ReleasePrimitiveArrayCritical(env, b, buf, 0); } JNIEXPORT void JNICALL Java_java_util_zip_Inflater_setDictionaryBuffer(JNIEnv *env, jclass cls, jlong addr, jlong bufferAddr, jint len) { ! jbyte *buf = jlong_to_ptr(bufferAddr); ! doSetDictionary(env, addr, buf, len); } ! static jlong doInflate(JNIEnv *env, jobject this, jlong addr, jbyte *input, jint inputLen, jbyte *output, jint outputLen) { z_stream *strm = jlong_to_ptr(addr); + jint inputUsed = 0, outputUsed = 0; + int finished = 0; + int needDict = 0; + int ret; strm->next_in = (Bytef *) input; strm->next_out = (Bytef *) output; strm->avail_in = inputLen; strm->avail_out = outputLen; ret = inflate(strm, Z_PARTIAL_FLUSH); switch (ret) { case Z_STREAM_END: finished = 1; /* fall through */
*** 188,198 **** jbyteArray inputArray, jint inputOff, jint inputLen, jbyteArray outputArray, jint outputOff, jint outputLen) { jbyte *input = (*env)->GetPrimitiveArrayCritical(env, inputArray, 0); jbyte *output; - jint ret; jlong retVal; if (input == NULL) { if (inputLen != 0 && (*env)->ExceptionOccurred(env) == NULL) JNU_ThrowOutOfMemoryError(env, 0); --- 178,187 ----
*** 204,244 **** if (outputLen != 0 && (*env)->ExceptionOccurred(env) == NULL) JNU_ThrowOutOfMemoryError(env, 0); return 0L; } ! ret = doInflate(addr, input + inputOff, inputLen, output + outputOff, ! outputLen); (*env)->ReleasePrimitiveArrayCritical(env, outputArray, output, 0); (*env)->ReleasePrimitiveArrayCritical(env, inputArray, input, 0); - retVal = checkInflateStatus(env, this, addr, inputLen, outputLen, ret ); return retVal; } JNIEXPORT jlong JNICALL Java_java_util_zip_Inflater_inflateBytesBuffer(JNIEnv *env, jobject this, jlong addr, jbyteArray inputArray, jint inputOff, jint inputLen, jlong outputBuffer, jint outputLen) { jbyte *input = (*env)->GetPrimitiveArrayCritical(env, inputArray, 0); jbyte *output; - jint ret; jlong retVal; if (input == NULL) { if (inputLen != 0 && (*env)->ExceptionOccurred(env) == NULL) JNU_ThrowOutOfMemoryError(env, 0); return 0L; } output = jlong_to_ptr(outputBuffer); ! ret = doInflate(addr, input + inputOff, inputLen, output, outputLen); (*env)->ReleasePrimitiveArrayCritical(env, inputArray, input, 0); - retVal = checkInflateStatus(env, this, addr, inputLen, outputLen, ret ); return retVal; } JNIEXPORT jlong JNICALL --- 193,233 ---- if (outputLen != 0 && (*env)->ExceptionOccurred(env) == NULL) JNU_ThrowOutOfMemoryError(env, 0); return 0L; } ! retVal = doInflate(env, this, addr, ! input + inputOff, inputLen, ! output + outputOff, outputLen); (*env)->ReleasePrimitiveArrayCritical(env, outputArray, output, 0); (*env)->ReleasePrimitiveArrayCritical(env, inputArray, input, 0); return retVal; } JNIEXPORT jlong JNICALL Java_java_util_zip_Inflater_inflateBytesBuffer(JNIEnv *env, jobject this, jlong addr, jbyteArray inputArray, jint inputOff, jint inputLen, jlong outputBuffer, jint outputLen) { jbyte *input = (*env)->GetPrimitiveArrayCritical(env, inputArray, 0); jbyte *output; jlong retVal; if (input == NULL) { if (inputLen != 0 && (*env)->ExceptionOccurred(env) == NULL) JNU_ThrowOutOfMemoryError(env, 0); return 0L; } output = jlong_to_ptr(outputBuffer); ! retVal = doInflate(env, this, addr, ! input + inputOff, inputLen, ! output, outputLen); (*env)->ReleasePrimitiveArrayCritical(env, inputArray, input, 0); return retVal; } JNIEXPORT jlong JNICALL
*** 246,268 **** jlong inputBuffer, jint inputLen, jbyteArray outputArray, jint outputOff, jint outputLen) { jbyte *input = jlong_to_ptr(inputBuffer); jbyte *output = (*env)->GetPrimitiveArrayCritical(env, outputArray, 0); - jint ret; jlong retVal; if (output == NULL) { if (outputLen != 0 && (*env)->ExceptionOccurred(env) == NULL) JNU_ThrowOutOfMemoryError(env, 0); return 0L; } ! ret = doInflate(addr, input, inputLen, output + outputOff, outputLen); (*env)->ReleasePrimitiveArrayCritical(env, outputArray, output, 0); - retVal = checkInflateStatus(env, this, addr, inputLen, outputLen, ret ); return retVal; } JNIEXPORT jlong JNICALL --- 235,257 ---- jlong inputBuffer, jint inputLen, jbyteArray outputArray, jint outputOff, jint outputLen) { jbyte *input = jlong_to_ptr(inputBuffer); jbyte *output = (*env)->GetPrimitiveArrayCritical(env, outputArray, 0); jlong retVal; if (output == NULL) { if (outputLen != 0 && (*env)->ExceptionOccurred(env) == NULL) JNU_ThrowOutOfMemoryError(env, 0); return 0L; } ! retVal = doInflate(env, this, addr, ! input, inputLen, ! output + outputOff, outputLen); (*env)->ReleasePrimitiveArrayCritical(env, outputArray, output, 0); return retVal; } JNIEXPORT jlong JNICALL
*** 270,285 **** jlong inputBuffer, jint inputLen, jlong outputBuffer, jint outputLen) { jbyte *input = jlong_to_ptr(inputBuffer); jbyte *output = jlong_to_ptr(outputBuffer); - jint ret; - jlong retVal; ! ret = doInflate(addr, input, inputLen, output, outputLen); ! retVal = checkInflateStatus(env, this, addr, inputLen, outputLen, ret); ! return retVal; } JNIEXPORT jint JNICALL Java_java_util_zip_Inflater_getAdler(JNIEnv *env, jclass cls, jlong addr) { --- 259,272 ---- jlong inputBuffer, jint inputLen, jlong outputBuffer, jint outputLen) { jbyte *input = jlong_to_ptr(inputBuffer); jbyte *output = jlong_to_ptr(outputBuffer); ! return doInflate(env, this, addr, ! input, inputLen, ! output, outputLen); } JNIEXPORT jint JNICALL Java_java_util_zip_Inflater_getAdler(JNIEnv *env, jclass cls, jlong addr) {
< prev index next >