src/share/native/java/util/zip/Inflater.c

Print this page




 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     ret = inflate(strm, Z_FINISH);
 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_BUF_ERROR:
 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_DATA_ERROR:
 166         ThrowDataFormatException(env, strm->msg);
 167         return 0;
 168     case Z_MEM_ERROR:
 169         JNU_ThrowOutOfMemoryError(env, 0);
 170         return 0;
 171     default:
 172         JNU_ThrowInternalError(env, strm->msg);
 173         return 0;
 174     }
 175 }
 176 
 177 JNIEXPORT jint JNICALL
 178 Java_java_util_zip_Inflater_getAdler(JNIEnv *env, jclass cls, jlong addr)
 179 {
 180     return ((z_stream *)jlong_to_ptr(addr))->adler;
 181 }
 182 
 183 JNIEXPORT void JNICALL