src/share/classes/com/sun/tools/javac/file/ZipFileIndex.java

changeset 1467
189b26e3818f
parent 1442
fcf89720ae71
child 2525
2eb010b6cb22
equal deleted inserted replaced
1466:b52a38d4536c 1467:189b26e3818f
546 get2ByteLittleEndian(endbuf, i + 20) == totalLength)) { 546 get2ByteLittleEndian(endbuf, i + 20) == totalLength)) {
547 i--; 547 i--;
548 } 548 }
549 549
550 if (i >= 0) { 550 if (i >= 0) {
551 zipDir = new byte[get4ByteLittleEndian(endbuf, i + 12) + 2]; 551 zipDir = new byte[get4ByteLittleEndian(endbuf, i + 12)];
552 zipDir[0] = endbuf[i + 10];
553 zipDir[1] = endbuf[i + 11];
554 int sz = get4ByteLittleEndian(endbuf, i + 16); 552 int sz = get4ByteLittleEndian(endbuf, i + 16);
555 // a negative offset or the entries field indicates a 553 // a negative offset or the entries field indicates a
556 // potential zip64 archive 554 // potential zip64 archive
557 if (sz < 0 || get2ByteLittleEndian(zipDir, 0) == 0xffff) { 555 if (sz < 0 || get2ByteLittleEndian(endbuf, i + 10) == 0xffff) {
558 throw new ZipFormatException("detected a zip64 archive"); 556 throw new ZipFormatException("detected a zip64 archive");
559 } 557 }
560 zipRandomFile.seek(start + sz); 558 zipRandomFile.seek(start + sz);
561 zipRandomFile.readFully(zipDir, 2, zipDir.length - 2); 559 zipRandomFile.readFully(zipDir, 0, zipDir.length);
562 return; 560 return;
563 } else { 561 } else {
564 endbufend = endbufpos + 21; 562 endbufend = endbufpos + 21;
565 } 563 }
566 } 564 }
567 throw new ZipException("cannot read zip file"); 565 throw new ZipException("cannot read zip file");
568 } 566 }
569 567
570 private void buildIndex() throws IOException { 568 private void buildIndex() throws IOException {
571 int entryCount = get2ByteLittleEndian(zipDir, 0); 569 int len = zipDir.length;
572 570
573 // Add each of the files 571 // Add each of the files
574 if (entryCount > 0) { 572 if (len > 0) {
575 directories = new LinkedHashMap<RelativeDirectory, DirectoryEntry>(); 573 directories = new LinkedHashMap<RelativeDirectory, DirectoryEntry>();
576 ArrayList<Entry> entryList = new ArrayList<Entry>(); 574 ArrayList<Entry> entryList = new ArrayList<Entry>();
577 int pos = 2; 575 for (int pos = 0; pos < len; ) {
578 for (int i = 0; i < entryCount; i++) {
579 pos = readEntry(pos, entryList, directories); 576 pos = readEntry(pos, entryList, directories);
580 } 577 }
581 578
582 // Add the accumulated dirs into the same list 579 // Add the accumulated dirs into the same list
583 for (RelativeDirectory d: directories.keySet()) { 580 for (RelativeDirectory d: directories.keySet()) {

mercurial