< prev index next >

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

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
+ * 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,12 +85,13 @@
             return jlong_zero;
         }
     }
 }
 
-static void checkSetDictionaryResult(JNIEnv *env, jlong addr, int res)
+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,52 +105,41 @@
 
 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);
+    jbyte *buf = (*env)->GetPrimitiveArrayCritical(env, b, 0);
     if (buf == NULL) /* out of memory */
         return;
-    res = inflateSetDictionary(jlong_to_ptr(addr), buf + off, len);
+    doSetDictionary(env, 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);
+    jbyte *buf = jlong_to_ptr(bufferAddr);
+    doSetDictionary(env, addr, buf, len);
 }
 
-static jint doInflate(jlong addr,
+static jlong doInflate(JNIEnv *env, jobject this, jlong addr,
                        jbyte *input, jint inputLen,
                        jbyte *output, jint outputLen)
 {
-    jint ret;
     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);
-    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 */

@@ -188,11 +178,10 @@
                                          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);

@@ -204,41 +193,41 @@
         if (outputLen != 0 && (*env)->ExceptionOccurred(env) == NULL)
             JNU_ThrowOutOfMemoryError(env, 0);
         return 0L;
     }
 
-    ret = doInflate(addr, input + inputOff, inputLen, output + outputOff,
-                    outputLen);
+    retVal = doInflate(env, this, 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);
+    retVal = doInflate(env, this, 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

@@ -246,23 +235,23 @@
                                          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);
+    retVal = doInflate(env, this, 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

@@ -270,16 +259,14 @@
                                          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;
+    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 >