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