130 jbyte *out_buf; 131 int ret; 132 133 in_buf = (*env)->GetPrimitiveArrayCritical(env, this_buf, 0); 134 if (in_buf == NULL) { 135 if (this_len != 0 && (*env)->ExceptionOccurred(env) == NULL) 136 JNU_ThrowOutOfMemoryError(env, 0); 137 return 0; 138 } 139 out_buf = (*env)->GetPrimitiveArrayCritical(env, b, 0); 140 if (out_buf == NULL) { 141 (*env)->ReleasePrimitiveArrayCritical(env, this_buf, in_buf, 0); 142 if (len != 0 && (*env)->ExceptionOccurred(env) == NULL) 143 JNU_ThrowOutOfMemoryError(env, 0); 144 return 0; 145 } 146 strm->next_in = (Bytef *) (in_buf + this_off); 147 strm->next_out = (Bytef *) (out_buf + off); 148 strm->avail_in = this_len; 149 strm->avail_out = len; 150 ret = inflate(strm, Z_PARTIAL_FLUSH); 151 (*env)->ReleasePrimitiveArrayCritical(env, b, out_buf, 0); 152 (*env)->ReleasePrimitiveArrayCritical(env, this_buf, in_buf, 0); 153 154 switch (ret) { 155 case Z_STREAM_END: 156 (*env)->SetBooleanField(env, this, finishedID, JNI_TRUE); 157 /* fall through */ 158 case Z_OK: 159 this_off += this_len - strm->avail_in; 160 (*env)->SetIntField(env, this, offID, this_off); 161 (*env)->SetIntField(env, this, lenID, strm->avail_in); 162 return (jint) (len - strm->avail_out); 163 case Z_NEED_DICT: 164 (*env)->SetBooleanField(env, this, needDictID, JNI_TRUE); 165 /* Might have consumed some input here! */ 166 this_off += this_len - strm->avail_in; 167 (*env)->SetIntField(env, this, offID, this_off); 168 (*env)->SetIntField(env, this, lenID, strm->avail_in); 169 return 0; 170 case Z_BUF_ERROR: 171 return 0; 172 case Z_DATA_ERROR: 173 ThrowDataFormatException(env, strm->msg); 174 return 0; 175 case Z_MEM_ERROR: 176 JNU_ThrowOutOfMemoryError(env, 0); 177 return 0; 178 default: 179 JNU_ThrowInternalError(env, strm->msg); 180 return 0; 181 } 182 } 183 184 JNIEXPORT jint JNICALL 185 Java_java_util_zip_Inflater_getAdler(JNIEnv *env, jclass cls, jlong addr) 186 { 187 return ((z_stream *)jlong_to_ptr(addr))->adler; 188 } 189 190 JNIEXPORT void JNICALL | 130 jbyte *out_buf; 131 int ret; 132 133 in_buf = (*env)->GetPrimitiveArrayCritical(env, this_buf, 0); 134 if (in_buf == NULL) { 135 if (this_len != 0 && (*env)->ExceptionOccurred(env) == NULL) 136 JNU_ThrowOutOfMemoryError(env, 0); 137 return 0; 138 } 139 out_buf = (*env)->GetPrimitiveArrayCritical(env, b, 0); 140 if (out_buf == NULL) { 141 (*env)->ReleasePrimitiveArrayCritical(env, this_buf, in_buf, 0); 142 if (len != 0 && (*env)->ExceptionOccurred(env) == NULL) 143 JNU_ThrowOutOfMemoryError(env, 0); 144 return 0; 145 } 146 strm->next_in = (Bytef *) (in_buf + this_off); 147 strm->next_out = (Bytef *) (out_buf + off); 148 strm->avail_in = this_len; 149 strm->avail_out = len; 150 151 /* The flush parameter of inflate() is set to Z_FINISH to skip 152 the allocation of a sliding window until necessary. */ 153 ret = inflate(strm, Z_FINISH); 154 (*env)->ReleasePrimitiveArrayCritical(env, b, out_buf, 0); 155 (*env)->ReleasePrimitiveArrayCritical(env, this_buf, in_buf, 0); 156 157 /* When flush is set to Z_FINISH, inflate() cannot return Z_OK. Instead it 158 will return Z_BUF_ERROR if it has not reached the end of the stream. 159 Here we keep the same processing for both these return codes. */ 160 switch (ret) { 161 case Z_STREAM_END: 162 (*env)->SetBooleanField(env, this, finishedID, JNI_TRUE); 163 /* fall through */ 164 case Z_OK: 165 case Z_BUF_ERROR: 166 this_off += this_len - strm->avail_in; 167 (*env)->SetIntField(env, this, offID, this_off); 168 (*env)->SetIntField(env, this, lenID, strm->avail_in); 169 return (jint) (len - strm->avail_out); 170 case Z_NEED_DICT: 171 (*env)->SetBooleanField(env, this, needDictID, JNI_TRUE); 172 /* Might have consumed some input here! */ 173 this_off += this_len - strm->avail_in; 174 (*env)->SetIntField(env, this, offID, this_off); 175 (*env)->SetIntField(env, this, lenID, strm->avail_in); 176 return 0; 177 case Z_DATA_ERROR: 178 ThrowDataFormatException(env, strm->msg); 179 return 0; 180 case Z_MEM_ERROR: 181 JNU_ThrowOutOfMemoryError(env, 0); 182 return 0; 183 default: 184 JNU_ThrowInternalError(env, strm->msg); 185 return 0; 186 } 187 } 188 189 JNIEXPORT jint JNICALL 190 Java_java_util_zip_Inflater_getAdler(JNIEnv *env, jclass cls, jlong addr) 191 { 192 return ((z_stream *)jlong_to_ptr(addr))->adler; 193 } 194 195 JNIEXPORT void JNICALL |