< prev index next >

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

Print this page

        

@@ -145,19 +145,26 @@
     }
     strm->next_in  = (Bytef *) (in_buf + this_off);
     strm->next_out = (Bytef *) (out_buf + off);
     strm->avail_in  = this_len;
     strm->avail_out = len;
-    ret = inflate(strm, Z_PARTIAL_FLUSH);
+
+    /* The flush parameter of inflate() is set to Z_FINISH to skip
+       the allocation of a sliding window until necessary. */
+    ret = inflate(strm, Z_FINISH);
     (*env)->ReleasePrimitiveArrayCritical(env, b, out_buf, 0);
     (*env)->ReleasePrimitiveArrayCritical(env, this_buf, in_buf, 0);
 
+    /* When flush is set to Z_FINISH, inflate() cannot return Z_OK. Instead it
+       will return Z_BUF_ERROR if it has not reached the end of the stream.
+       Here we keep the same processing for both these return codes. */
     switch (ret) {
     case Z_STREAM_END:
         (*env)->SetBooleanField(env, this, finishedID, JNI_TRUE);
         /* fall through */
     case Z_OK:
+    case Z_BUF_ERROR:
         this_off += this_len - strm->avail_in;
         (*env)->SetIntField(env, this, offID, this_off);
         (*env)->SetIntField(env, this, lenID, strm->avail_in);
         return (jint) (len - strm->avail_out);
     case Z_NEED_DICT:

@@ -165,12 +172,10 @@
         /* Might have consumed some input here! */
         this_off += this_len - strm->avail_in;
         (*env)->SetIntField(env, this, offID, this_off);
         (*env)->SetIntField(env, this, lenID, strm->avail_in);
         return 0;
-    case Z_BUF_ERROR:
-        return 0;
     case Z_DATA_ERROR:
         ThrowDataFormatException(env, strm->msg);
         return 0;
     case Z_MEM_ERROR:
         JNU_ThrowOutOfMemoryError(env, 0);
< prev index next >