src/share/native/com/sun/java/util/jar/pack/zip.cpp

Print this page




 434 static jlong read_input_via_gzip(unpacker* u,
 435                                   void* buf, jlong minlen, jlong maxlen) {
 436   assert(minlen <= maxlen);  // don't talk nonsense
 437   jlong numread = 0;
 438   char* bufptr = (char*) buf;
 439   char* inbuf = u->gzin->inbuf;
 440   size_t inbuflen = sizeof(u->gzin->inbuf);
 441   unpacker::read_input_fn_t read_gzin_fn =
 442     (unpacker::read_input_fn_t) u->gzin->read_input_fn;
 443   z_stream& zs = *(z_stream*) u->gzin->zstream;
 444   while (numread < minlen) {
 445     int readlen = (1 << 16);  // pretty arbitrary
 446     if (readlen > (maxlen - numread))
 447       readlen = (int)(maxlen - numread);
 448     zs.next_out = (uchar*) bufptr;
 449     zs.avail_out = readlen;
 450     if (zs.avail_in == 0) {
 451       zs.avail_in = (int) read_gzin_fn(u, inbuf, 1, inbuflen);
 452       zs.next_in = (uchar*) inbuf;
 453     }
 454     int error = inflate(&zs, Z_NO_FLUSH);
 455     if (error != Z_OK && error != Z_STREAM_END) {



 456       u->abort("error inflating input");
 457       break;
 458     }
 459     int nr = readlen - zs.avail_out;
 460     numread += nr;
 461     bufptr += nr;
 462     assert(numread <= maxlen);
 463     if (error == Z_STREAM_END) {
 464       enum { TRAILER_LEN = 8 };
 465       // skip 8-byte trailer
 466       if (zs.avail_in >= TRAILER_LEN) {
 467         zs.avail_in -= TRAILER_LEN;
 468       } else {
 469         // Bug: 5023768,we read past the TRAILER_LEN to see if there is
 470         // any extraneous data, as we dont support concatenated .gz
 471         // files just yet.
 472         int extra = (int) read_gzin_fn(u, inbuf, 1, inbuflen);
 473         zs.avail_in += extra - TRAILER_LEN;
 474       }
 475       // %%% should check final CRC and length here




 434 static jlong read_input_via_gzip(unpacker* u,
 435                                   void* buf, jlong minlen, jlong maxlen) {
 436   assert(minlen <= maxlen);  // don't talk nonsense
 437   jlong numread = 0;
 438   char* bufptr = (char*) buf;
 439   char* inbuf = u->gzin->inbuf;
 440   size_t inbuflen = sizeof(u->gzin->inbuf);
 441   unpacker::read_input_fn_t read_gzin_fn =
 442     (unpacker::read_input_fn_t) u->gzin->read_input_fn;
 443   z_stream& zs = *(z_stream*) u->gzin->zstream;
 444   while (numread < minlen) {
 445     int readlen = (1 << 16);  // pretty arbitrary
 446     if (readlen > (maxlen - numread))
 447       readlen = (int)(maxlen - numread);
 448     zs.next_out = (uchar*) bufptr;
 449     zs.avail_out = readlen;
 450     if (zs.avail_in == 0) {
 451       zs.avail_in = (int) read_gzin_fn(u, inbuf, 1, inbuflen);
 452       zs.next_in = (uchar*) inbuf;
 453     }
 454     // When flush is set to Z_FINISH, inflate() cannot return Z_OK. Instead it
 455     // will return Z_BUF_ERROR if it has not reached the end of the stream.
 456     // So, the only normal return codes are Z_BUF_ERROR and Z_STREAM_END.
 457     int error = inflate(&zs, Z_FINISH);
 458     if (error != Z_BUF_ERROR && error != Z_STREAM_END) {
 459       u->abort("error inflating input");
 460       break;
 461     }
 462     int nr = readlen - zs.avail_out;
 463     numread += nr;
 464     bufptr += nr;
 465     assert(numread <= maxlen);
 466     if (error == Z_STREAM_END) {
 467       enum { TRAILER_LEN = 8 };
 468       // skip 8-byte trailer
 469       if (zs.avail_in >= TRAILER_LEN) {
 470         zs.avail_in -= TRAILER_LEN;
 471       } else {
 472         // Bug: 5023768,we read past the TRAILER_LEN to see if there is
 473         // any extraneous data, as we dont support concatenated .gz
 474         // files just yet.
 475         int extra = (int) read_gzin_fn(u, inbuf, 1, inbuflen);
 476         zs.avail_in += extra - TRAILER_LEN;
 477       }
 478       // %%% should check final CRC and length here