118 jbyte *in_buf; 119 jbyte *out_buf; 120 int ret; 121 /* 122 * Avoid excess copying. 123 * zlib stream usually has a few bytes of overhead for header info 124 * (depends on the underlying data) 125 * 126 * (a) 5 bytes per 16KB 127 * (b) 6 bytes for entire stream 128 * (c) 4 bytes for gzip header 129 * (d) 2 bytes for crc 130 * 131 * Use 20 bytes as the "safe cutoff" number. 132 */ 133 jint in_len = MIN2(this_len, len + 20); 134 jint consumed; 135 136 in_buf = (jbyte *) malloc(in_len); 137 if (in_buf == 0) { 138 JNU_ThrowOutOfMemoryError(env, 0); 139 return 0; 140 } 141 (*env)->GetByteArrayRegion(env, this_buf, this_off, in_len, in_buf); 142 143 out_buf = (jbyte *) malloc(len); 144 if (out_buf == 0) { 145 free(in_buf); 146 JNU_ThrowOutOfMemoryError(env, 0); 147 return 0; 148 } 149 150 strm->next_in = (Bytef *) in_buf; 151 strm->next_out = (Bytef *) out_buf; 152 strm->avail_in = in_len; 153 strm->avail_out = len; 154 ret = inflate(strm, Z_PARTIAL_FLUSH); 155 156 if (ret == Z_STREAM_END || ret == Z_OK) { 157 (*env)->SetByteArrayRegion(env, b, off, len - strm->avail_out, out_buf); 158 } 159 free(out_buf); 160 free(in_buf); 161 162 switch (ret) { 163 case Z_STREAM_END: 164 (*env)->SetBooleanField(env, this, finishedID, JNI_TRUE); 165 /* fall through */ | 118 jbyte *in_buf; 119 jbyte *out_buf; 120 int ret; 121 /* 122 * Avoid excess copying. 123 * zlib stream usually has a few bytes of overhead for header info 124 * (depends on the underlying data) 125 * 126 * (a) 5 bytes per 16KB 127 * (b) 6 bytes for entire stream 128 * (c) 4 bytes for gzip header 129 * (d) 2 bytes for crc 130 * 131 * Use 20 bytes as the "safe cutoff" number. 132 */ 133 jint in_len = MIN2(this_len, len + 20); 134 jint consumed; 135 136 in_buf = (jbyte *) malloc(in_len); 137 if (in_buf == 0) { 138 if (in_len != 0) 139 JNU_ThrowOutOfMemoryError(env, 0); 140 return 0; 141 } 142 (*env)->GetByteArrayRegion(env, this_buf, this_off, in_len, in_buf); 143 144 out_buf = (jbyte *) malloc(len); 145 if (out_buf == 0) { 146 free(in_buf); 147 if (len != 0) 148 JNU_ThrowOutOfMemoryError(env, 0); 149 return 0; 150 } 151 152 strm->next_in = (Bytef *) in_buf; 153 strm->next_out = (Bytef *) out_buf; 154 strm->avail_in = in_len; 155 strm->avail_out = len; 156 ret = inflate(strm, Z_PARTIAL_FLUSH); 157 158 if (ret == Z_STREAM_END || ret == Z_OK) { 159 (*env)->SetByteArrayRegion(env, b, off, len - strm->avail_out, out_buf); 160 } 161 free(out_buf); 162 free(in_buf); 163 164 switch (ret) { 165 case Z_STREAM_END: 166 (*env)->SetBooleanField(env, this, finishedID, JNI_TRUE); 167 /* fall through */ |