< prev index next >

src/java.base/share/classes/java/util/zip/ZipInputStream.java

Print this page
0000000: Optimize ZipCoder
Reviewed-by: sherman


 280         } catch (EOFException e) {
 281             return null;
 282         }
 283         if (get32(tmpbuf, 0) != LOCSIG) {
 284             return null;
 285         }
 286         // get flag first, we need check EFS.
 287         flag = get16(tmpbuf, LOCFLG);
 288         // get the entry name and create the ZipEntry first
 289         int len = get16(tmpbuf, LOCNAM);
 290         int blen = b.length;
 291         if (len > blen) {
 292             do {
 293                 blen = blen * 2;
 294             } while (len > blen);
 295             b = new byte[blen];
 296         }
 297         readFully(b, 0, len);
 298         // Force to use UTF-8 if the EFS bit is ON, even the cs is NOT UTF-8
 299         ZipEntry e = createZipEntry(((flag & EFS) != 0)
 300                                     ? zc.toStringUTF8(b, len)
 301                                     : zc.toString(b, len));
 302         // now get the remaining fields for the entry
 303         if ((flag & 1) == 1) {
 304             throw new ZipException("encrypted ZIP entry not supported");
 305         }
 306         e.method = get16(tmpbuf, LOCHOW);
 307         e.xdostime = get32(tmpbuf, LOCTIM);
 308         if ((flag & 8) == 8) {
 309             /* "Data Descriptor" present */
 310             if (e.method != DEFLATED) {
 311                 throw new ZipException(
 312                         "only DEFLATED entries can have EXT descriptor");
 313             }
 314         } else {
 315             e.crc = get32(tmpbuf, LOCCRC);
 316             e.csize = get32(tmpbuf, LOCSIZ);
 317             e.size = get32(tmpbuf, LOCLEN);
 318         }
 319         len = get16(tmpbuf, LOCEXT);
 320         if (len > 0) {




 280         } catch (EOFException e) {
 281             return null;
 282         }
 283         if (get32(tmpbuf, 0) != LOCSIG) {
 284             return null;
 285         }
 286         // get flag first, we need check EFS.
 287         flag = get16(tmpbuf, LOCFLG);
 288         // get the entry name and create the ZipEntry first
 289         int len = get16(tmpbuf, LOCNAM);
 290         int blen = b.length;
 291         if (len > blen) {
 292             do {
 293                 blen = blen * 2;
 294             } while (len > blen);
 295             b = new byte[blen];
 296         }
 297         readFully(b, 0, len);
 298         // Force to use UTF-8 if the EFS bit is ON, even the cs is NOT UTF-8
 299         ZipEntry e = createZipEntry(((flag & EFS) != 0)
 300                                     ? ZipCoder.toStringUTF8(b, len)
 301                                     : zc.toString(b, len));
 302         // now get the remaining fields for the entry
 303         if ((flag & 1) == 1) {
 304             throw new ZipException("encrypted ZIP entry not supported");
 305         }
 306         e.method = get16(tmpbuf, LOCHOW);
 307         e.xdostime = get32(tmpbuf, LOCTIM);
 308         if ((flag & 8) == 8) {
 309             /* "Data Descriptor" present */
 310             if (e.method != DEFLATED) {
 311                 throw new ZipException(
 312                         "only DEFLATED entries can have EXT descriptor");
 313             }
 314         } else {
 315             e.crc = get32(tmpbuf, LOCCRC);
 316             e.csize = get32(tmpbuf, LOCSIZ);
 317             e.size = get32(tmpbuf, LOCLEN);
 318         }
 319         len = get16(tmpbuf, LOCEXT);
 320         if (len > 0) {


< prev index next >