< prev index next >

src/java.base/share/native/libzip/Deflater.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

@@ -74,12 +74,13 @@
             return jlong_zero;
         }
     }
 }
 
-static void checkSetDictionaryResult(JNIEnv *env, jlong addr, jint res)
+static void doSetDictionary(JNIEnv *env, jlong addr, jbyte *buf, jint len)
 {
+    int res = deflateSetDictionary(jlong_to_ptr(addr), (Bytef *) buf, len);
     switch (res) {
     case Z_OK:
         break;
     case Z_STREAM_ERROR:
         JNU_ThrowIllegalArgumentException(env, 0);

@@ -92,64 +93,44 @@
 
 JNIEXPORT void JNICALL
 Java_java_util_zip_Deflater_setDictionary(JNIEnv *env, jclass cls, jlong addr,
                                           jbyteArray b, jint off, jint len)
 {
-    int res;
-    Bytef *buf = (*env)->GetPrimitiveArrayCritical(env, b, 0);
+    jbyte *buf = (*env)->GetPrimitiveArrayCritical(env, b, 0);
     if (buf == NULL) /* out of memory */
         return;
-    res = deflateSetDictionary(jlong_to_ptr(addr), buf, len);
+    doSetDictionary(env, addr, buf + off, len);
     (*env)->ReleasePrimitiveArrayCritical(env, b, buf, 0);
-    checkSetDictionaryResult(env, addr, res);
 }
 
 JNIEXPORT void JNICALL
 Java_java_util_zip_Deflater_setDictionaryBuffer(JNIEnv *env, jclass cls, jlong addr,
                                           jlong bufferAddr, jint len)
 {
-    int res;
-    Bytef *buf = jlong_to_ptr(bufferAddr);
-    res = deflateSetDictionary(jlong_to_ptr(addr), buf, len);
-    checkSetDictionaryResult(env, addr, res);
+    jbyte *buf = jlong_to_ptr(bufferAddr);
+    doSetDictionary(env, addr, buf, len);
 }
 
-static jint doDeflate(JNIEnv *env, jlong addr,
+static jlong doDeflate(JNIEnv *env, jobject this, jlong addr,
                        jbyte *input, jint inputLen,
                        jbyte *output, jint outputLen,
                        jint flush, jint params)
 {
     z_stream *strm = jlong_to_ptr(addr);
+    jint inputUsed = 0, outputUsed = 0;
+    int finished = 0;
     int setParams = params & 1;
-    int res;
 
     strm->next_in  = (Bytef *) input;
     strm->next_out = (Bytef *) output;
     strm->avail_in  = inputLen;
     strm->avail_out = outputLen;
 
     if (setParams) {
         int strategy = (params >> 1) & 3;
         int level = params >> 3;
-        res = deflateParams(strm, level, strategy);
-    } else {
-        res = deflate(strm, flush);
-    }
-    return res;
-}
-
-static jlong checkDeflateStatus(JNIEnv *env, jlong addr,
-                        jint inputLen,
-                        jint outputLen,
-                        jint params, int res)
-{
-    z_stream *strm = jlong_to_ptr(addr);
-    jint inputUsed = 0, outputUsed = 0;
-    int finished = 0;
-    int setParams = params & 1;
-
-    if (setParams) {
+        int res = deflateParams(strm, level, strategy);
         switch (res) {
         case Z_OK:
             setParams = 0;
             /* fall through */
         case Z_BUF_ERROR:

@@ -159,10 +140,11 @@
         default:
             JNU_ThrowInternalError(env, strm->msg);
             return 0;
         }
     } else {
+        int res = deflate(strm, flush);
         switch (res) {
         case Z_STREAM_END:
             finished = 1;
             /* fall through */
         case Z_OK:

@@ -185,12 +167,10 @@
                                          jint flush, jint params)
 {
     jbyte *input = (*env)->GetPrimitiveArrayCritical(env, inputArray, 0);
     jbyte *output;
     jlong retVal;
-    jint res;
-
     if (input == NULL) {
         if (inputLen != 0 && (*env)->ExceptionOccurred(env) == NULL)
             JNU_ThrowOutOfMemoryError(env, 0);
         return 0L;
     }

@@ -200,17 +180,18 @@
         if (outputLen != 0 && (*env)->ExceptionOccurred(env) == NULL)
             JNU_ThrowOutOfMemoryError(env, 0);
         return 0L;
     }
 
-     res = doDeflate(env, addr, input + inputOff, inputLen,output + outputOff,
-                     outputLen, flush, params);
+    retVal = doDeflate(env, this, addr,
+            input + inputOff, inputLen,
+            output + outputOff, outputLen,
+            flush, params);
 
     (*env)->ReleasePrimitiveArrayCritical(env, outputArray, output, 0);
     (*env)->ReleasePrimitiveArrayCritical(env, inputArray, input, 0);
 
-    retVal = checkDeflateStatus(env, addr, inputLen, outputLen, params, res);
     return retVal;
 }
 
 
 JNIEXPORT jlong JNICALL

@@ -220,24 +201,24 @@
                                          jint flush, jint params)
 {
     jbyte *input = (*env)->GetPrimitiveArrayCritical(env, inputArray, 0);
     jbyte *output;
     jlong retVal;
-    jint res;
     if (input == NULL) {
         if (inputLen != 0 && (*env)->ExceptionOccurred(env) == NULL)
             JNU_ThrowOutOfMemoryError(env, 0);
         return 0L;
     }
     output = jlong_to_ptr(outputBuffer);
 
-    res = doDeflate(env, addr, input + inputOff, inputLen, output, outputLen,
-                    flush, params);
+    retVal = doDeflate(env, this, addr,
+            input + inputOff, inputLen,
+            output, outputLen,
+            flush, params);
 
     (*env)->ReleasePrimitiveArrayCritical(env, inputArray, input, 0);
 
-    retVal = checkDeflateStatus(env, addr, inputLen, outputLen, params, res);
     return retVal;
 }
 
 JNIEXPORT jlong JNICALL
 Java_java_util_zip_Deflater_deflateBufferBytes(JNIEnv *env, jobject this, jlong addr,

@@ -246,22 +227,23 @@
                                          jint flush, jint params)
 {
     jbyte *input = jlong_to_ptr(inputBuffer);
     jbyte *output = (*env)->GetPrimitiveArrayCritical(env, outputArray, 0);
     jlong retVal;
-    jint res;
     if (output == NULL) {
         if (outputLen != 0 && (*env)->ExceptionOccurred(env) == NULL)
             JNU_ThrowOutOfMemoryError(env, 0);
         return 0L;
     }
 
-    res = doDeflate(env, addr, input, inputLen, output + outputOff, outputLen,
-                    flush, params);
+    retVal = doDeflate(env, this, addr,
+            input, inputLen,
+            output + outputOff, outputLen,
+            flush, params);
+
     (*env)->ReleasePrimitiveArrayCritical(env, outputArray, input, 0);
 
-    retVal = checkDeflateStatus(env, addr, inputLen, outputLen, params, res);
     return retVal;
 }
 
 JNIEXPORT jlong JNICALL
 Java_java_util_zip_Deflater_deflateBufferBuffer(JNIEnv *env, jobject this, jlong addr,

@@ -269,16 +251,15 @@
                                          jlong outputBuffer, jint outputLen,
                                          jint flush, jint params)
 {
     jbyte *input = jlong_to_ptr(inputBuffer);
     jbyte *output = jlong_to_ptr(outputBuffer);
-    jlong retVal;
-    jint res;
 
-    res = doDeflate(env, addr, input, inputLen, output, outputLen, flush, params);
-    retVal = checkDeflateStatus(env, addr, inputLen, outputLen, params, res);
-    return retVal;
+    return doDeflate(env, this, addr,
+            input, inputLen,
+            output, outputLen,
+            flush, params);
 }
 
 JNIEXPORT jint JNICALL
 Java_java_util_zip_Deflater_getAdler(JNIEnv *env, jclass cls, jlong addr)
 {
< prev index next >