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

Print this page




 101     int res;
 102     if (buf == 0) {/* out of memory */
 103         return;
 104     }
 105     res = deflateSetDictionary((z_stream *)jlong_to_ptr(strm), buf + off, len);
 106     (*env)->ReleasePrimitiveArrayCritical(env, b, buf, 0);
 107     switch (res) {
 108     case Z_OK:
 109         break;
 110     case Z_STREAM_ERROR:
 111         JNU_ThrowIllegalArgumentException(env, 0);
 112         break;
 113     default:
 114         JNU_ThrowInternalError(env, ((z_stream *)jlong_to_ptr(strm))->msg);
 115         break;
 116     }
 117 }
 118 
 119 JNIEXPORT jint JNICALL
 120 Java_java_util_zip_Deflater_deflateBytes(JNIEnv *env, jobject this,
 121                                          jarray b, jint off, jint len)
 122 {
 123     z_stream *strm = jlong_to_ptr((*env)->GetLongField(env, this, strmID));
 124 
 125     if (strm == 0) {
 126         JNU_ThrowNullPointerException(env, 0);
 127         return 0;
 128     } else {
 129         jarray this_buf = (*env)->GetObjectField(env, this, bufID);
 130         jint this_off = (*env)->GetIntField(env, this, offID);
 131         jint this_len = (*env)->GetIntField(env, this, lenID);
 132         jbyte *in_buf;
 133         jbyte *out_buf;
 134         int res;
 135         if ((*env)->GetBooleanField(env, this, setParamsID)) {
 136             int level = (*env)->GetIntField(env, this, levelID);
 137             int strategy = (*env)->GetIntField(env, this, strategyID);
 138 
 139             in_buf = (jbyte *) malloc(this_len);
 140             if (in_buf == 0) {
 141                 JNU_ThrowOutOfMemoryError(env, 0);


 180             jboolean finish = (*env)->GetBooleanField(env, this, finishID);
 181 
 182             in_buf = (jbyte *) malloc(this_len);
 183             if (in_buf == 0) {
 184                 JNU_ThrowOutOfMemoryError(env, 0);
 185                 return 0;
 186             }
 187             (*env)->GetByteArrayRegion(env, this_buf, this_off, this_len, in_buf);
 188 
 189             out_buf = (jbyte *) malloc(len);
 190             if (out_buf == 0) {
 191                 free(in_buf);
 192                 JNU_ThrowOutOfMemoryError(env, 0);
 193                 return 0;
 194             }
 195 
 196             strm->next_in = (Bytef *) in_buf;
 197             strm->next_out = (Bytef *) out_buf;
 198             strm->avail_in = this_len;
 199             strm->avail_out = len;
 200             res = deflate(strm, finish ? Z_FINISH : Z_NO_FLUSH);
 201 
 202             if (res == Z_STREAM_END || res == Z_OK) {
 203                 (*env)->SetByteArrayRegion(env, b, off, len - strm->avail_out, out_buf);
 204             }
 205             free(out_buf);
 206             free(in_buf);
 207 
 208             switch (res) {
 209             case Z_STREAM_END:
 210                 (*env)->SetBooleanField(env, this, finishedID, JNI_TRUE);
 211                 /* fall through */
 212             case Z_OK:
 213                 this_off += this_len - strm->avail_in;
 214                 (*env)->SetIntField(env, this, offID, this_off);
 215                 (*env)->SetIntField(env, this, lenID, strm->avail_in);
 216                 return len - strm->avail_out;
 217             case Z_BUF_ERROR:
 218                 return 0;
 219             default:
 220                 JNU_ThrowInternalError(env, strm->msg);




 101     int res;
 102     if (buf == 0) {/* out of memory */
 103         return;
 104     }
 105     res = deflateSetDictionary((z_stream *)jlong_to_ptr(strm), buf + off, len);
 106     (*env)->ReleasePrimitiveArrayCritical(env, b, buf, 0);
 107     switch (res) {
 108     case Z_OK:
 109         break;
 110     case Z_STREAM_ERROR:
 111         JNU_ThrowIllegalArgumentException(env, 0);
 112         break;
 113     default:
 114         JNU_ThrowInternalError(env, ((z_stream *)jlong_to_ptr(strm))->msg);
 115         break;
 116     }
 117 }
 118 
 119 JNIEXPORT jint JNICALL
 120 Java_java_util_zip_Deflater_deflateBytes(JNIEnv *env, jobject this,
 121                                          jarray b, jint off, jint len, jint flush)
 122 {
 123     z_stream *strm = jlong_to_ptr((*env)->GetLongField(env, this, strmID));
 124 
 125     if (strm == 0) {
 126         JNU_ThrowNullPointerException(env, 0);
 127         return 0;
 128     } else {
 129         jarray this_buf = (*env)->GetObjectField(env, this, bufID);
 130         jint this_off = (*env)->GetIntField(env, this, offID);
 131         jint this_len = (*env)->GetIntField(env, this, lenID);
 132         jbyte *in_buf;
 133         jbyte *out_buf;
 134         int res;
 135         if ((*env)->GetBooleanField(env, this, setParamsID)) {
 136             int level = (*env)->GetIntField(env, this, levelID);
 137             int strategy = (*env)->GetIntField(env, this, strategyID);
 138 
 139             in_buf = (jbyte *) malloc(this_len);
 140             if (in_buf == 0) {
 141                 JNU_ThrowOutOfMemoryError(env, 0);


 180             jboolean finish = (*env)->GetBooleanField(env, this, finishID);
 181 
 182             in_buf = (jbyte *) malloc(this_len);
 183             if (in_buf == 0) {
 184                 JNU_ThrowOutOfMemoryError(env, 0);
 185                 return 0;
 186             }
 187             (*env)->GetByteArrayRegion(env, this_buf, this_off, this_len, in_buf);
 188 
 189             out_buf = (jbyte *) malloc(len);
 190             if (out_buf == 0) {
 191                 free(in_buf);
 192                 JNU_ThrowOutOfMemoryError(env, 0);
 193                 return 0;
 194             }
 195 
 196             strm->next_in = (Bytef *) in_buf;
 197             strm->next_out = (Bytef *) out_buf;
 198             strm->avail_in = this_len;
 199             strm->avail_out = len;
 200             res = deflate(strm, finish ? Z_FINISH : flush);
 201 
 202             if (res == Z_STREAM_END || res == Z_OK) {
 203                 (*env)->SetByteArrayRegion(env, b, off, len - strm->avail_out, out_buf);
 204             }
 205             free(out_buf);
 206             free(in_buf);
 207 
 208             switch (res) {
 209             case Z_STREAM_END:
 210                 (*env)->SetBooleanField(env, this, finishedID, JNI_TRUE);
 211                 /* fall through */
 212             case Z_OK:
 213                 this_off += this_len - strm->avail_in;
 214                 (*env)->SetIntField(env, this, offID, this_off);
 215                 (*env)->SetIntField(env, this, lenID, strm->avail_in);
 216                 return len - strm->avail_out;
 217             case Z_BUF_ERROR:
 218                 return 0;
 219             default:
 220                 JNU_ThrowInternalError(env, strm->msg);