src/share/classes/com/sun/java/util/jar/pack/PackageReader.java

Print this page
rev 3516 : 7021582: convert jar/zip code and tests to use try-with-resources
Reviewed-by: XXX


 523                 }
 524                 cp_Descr_name.doneDisbursing();
 525                 cp_Descr_type.doneDisbursing();
 526                 break;
 527             case CONSTANT_Fieldref:
 528                 readMemberRefs(tag, cpMap, cp_Field_class, cp_Field_desc);
 529                 break;
 530             case CONSTANT_Methodref:
 531                 readMemberRefs(tag, cpMap, cp_Method_class, cp_Method_desc);
 532                 break;
 533             case CONSTANT_InterfaceMethodref:
 534                 readMemberRefs(tag, cpMap, cp_Imethod_class, cp_Imethod_desc);
 535                 break;
 536             default:
 537                 assert(false);
 538             }
 539 
 540             Index index = initCPIndex(tag, cpMap);
 541 
 542             if (optDumpBands) {
 543                 PrintStream ps = new PrintStream(getDumpStream(index, ".idx"));
 544                 printArrayTo(ps, index.cpMap, 0, index.cpMap.length);
 545                 ps.close();
 546             }
 547         }
 548 
 549         cp_bands.doneDisbursing();
 550 
 551         setBandIndexes();
 552     }
 553 
 554     void readUtf8Bands(Entry[] cpMap) throws IOException {
 555         //  cp_Utf8:
 556         //        *cp_Utf8_prefix :DELTA5
 557         //        *cp_Utf8_suffix :UNSIGNED5
 558         //        *cp_Utf8_chars :CHAR3
 559         //        *cp_Utf8_big_suffix :DELTA5
 560         //        (*cp_Utf8_big_chars :DELTA5)
 561         //          ** length(cp_Utf8_big_suffix)
 562         int len = cpMap.length;
 563         if (len == 0)
 564             return;  // nothing to read
 565 


 811         file_bands.doneDisbursing();
 812 
 813         if (archiveSize1 != 0 && !in.atLimit()) {
 814             throw new RuntimeException("Predicted archive_size "+
 815                                        archiveSize1+" != "+
 816                                        (in.getBytesServed()-archiveSize0));
 817         }
 818     }
 819 
 820     void readAttrDefs() throws IOException {
 821         //  attr_definition_bands:
 822         //        *attr_definition_headers :BYTE1
 823         //        *attr_definition_name :UNSIGNED5  (cp_Utf8)
 824         //        *attr_definition_layout :UNSIGNED5  (cp_Utf8)
 825         attr_definition_headers.expectLength(numAttrDefs);
 826         attr_definition_name.expectLength(numAttrDefs);
 827         attr_definition_layout.expectLength(numAttrDefs);
 828         attr_definition_headers.readFrom(in);
 829         attr_definition_name.readFrom(in);
 830         attr_definition_layout.readFrom(in);
 831         PrintStream dump = !optDumpBands ? null
 832             : new PrintStream(getDumpStream(attr_definition_headers, ".def"));

 833         for (int i = 0; i < numAttrDefs; i++) {
 834             int       header = attr_definition_headers.getByte();
 835             Utf8Entry name   = (Utf8Entry) attr_definition_name.getRef();
 836             Utf8Entry layout = (Utf8Entry) attr_definition_layout.getRef();
 837             int       ctype  = (header &  ADH_CONTEXT_MASK);
 838             int       index  = (header >> ADH_BIT_SHIFT) - ADH_BIT_IS_LSB;
 839             Attribute.Layout def = new Attribute.Layout(ctype,
 840                                                         name.stringValue(),
 841                                                         layout.stringValue());
 842             // Check layout string for Java 6 extensions.
 843             String pvLayout = def.layoutForPackageMajver(getPackageMajver());
 844             if (!pvLayout.equals(def.layout())) {
 845                 throw new IOException("Bad attribute layout in version 150 archive: "+def.layout());
 846             }
 847             this.setAttributeLayoutIndex(def, index);
 848             if (dump != null)  dump.println(index+" "+def);
 849         }
 850         if (dump != null)  dump.close();
 851         attr_definition_headers.doneDisbursing();
 852         attr_definition_name.doneDisbursing();
 853         attr_definition_layout.doneDisbursing();
 854         // Attribute layouts define bands, one per layout element.
 855         // Create them now, all at once.
 856         makeNewAttributeBands();
 857         attr_definition_bands.doneDisbursing();
 858     }
 859 
 860     void readInnerClasses() throws IOException {
 861         //  ic_bands:
 862         //        *ic_this_class :UDELTA5  (cp_Class)
 863         //        *ic_flags :UNSIGNED5
 864         //        *ic_outer_class :DELTA5  (null or cp_Class)
 865         //        *ic_name :DELTA5  (null or cp_Utf8)
 866         ic_this_class.expectLength(numInnerClasses);
 867         ic_this_class.readFrom(in);
 868         ic_flags.expectLength(numInnerClasses);
 869         ic_flags.readFrom(in);
 870         int longICCount = 0;




 523                 }
 524                 cp_Descr_name.doneDisbursing();
 525                 cp_Descr_type.doneDisbursing();
 526                 break;
 527             case CONSTANT_Fieldref:
 528                 readMemberRefs(tag, cpMap, cp_Field_class, cp_Field_desc);
 529                 break;
 530             case CONSTANT_Methodref:
 531                 readMemberRefs(tag, cpMap, cp_Method_class, cp_Method_desc);
 532                 break;
 533             case CONSTANT_InterfaceMethodref:
 534                 readMemberRefs(tag, cpMap, cp_Imethod_class, cp_Imethod_desc);
 535                 break;
 536             default:
 537                 assert(false);
 538             }
 539 
 540             Index index = initCPIndex(tag, cpMap);
 541 
 542             if (optDumpBands) {
 543                 try (PrintStream ps = new PrintStream(getDumpStream(index, ".idx"))) {
 544                     printArrayTo(ps, index.cpMap, 0, index.cpMap.length);
 545                 }
 546             }
 547         }
 548 
 549         cp_bands.doneDisbursing();
 550 
 551         setBandIndexes();
 552     }
 553 
 554     void readUtf8Bands(Entry[] cpMap) throws IOException {
 555         //  cp_Utf8:
 556         //        *cp_Utf8_prefix :DELTA5
 557         //        *cp_Utf8_suffix :UNSIGNED5
 558         //        *cp_Utf8_chars :CHAR3
 559         //        *cp_Utf8_big_suffix :DELTA5
 560         //        (*cp_Utf8_big_chars :DELTA5)
 561         //          ** length(cp_Utf8_big_suffix)
 562         int len = cpMap.length;
 563         if (len == 0)
 564             return;  // nothing to read
 565 


 811         file_bands.doneDisbursing();
 812 
 813         if (archiveSize1 != 0 && !in.atLimit()) {
 814             throw new RuntimeException("Predicted archive_size "+
 815                                        archiveSize1+" != "+
 816                                        (in.getBytesServed()-archiveSize0));
 817         }
 818     }
 819 
 820     void readAttrDefs() throws IOException {
 821         //  attr_definition_bands:
 822         //        *attr_definition_headers :BYTE1
 823         //        *attr_definition_name :UNSIGNED5  (cp_Utf8)
 824         //        *attr_definition_layout :UNSIGNED5  (cp_Utf8)
 825         attr_definition_headers.expectLength(numAttrDefs);
 826         attr_definition_name.expectLength(numAttrDefs);
 827         attr_definition_layout.expectLength(numAttrDefs);
 828         attr_definition_headers.readFrom(in);
 829         attr_definition_name.readFrom(in);
 830         attr_definition_layout.readFrom(in);
 831         try (PrintStream dump = !optDumpBands ? null
 832                  : new PrintStream(getDumpStream(attr_definition_headers, ".def")))
 833         {
 834             for (int i = 0; i < numAttrDefs; i++) {
 835                 int       header = attr_definition_headers.getByte();
 836                 Utf8Entry name   = (Utf8Entry) attr_definition_name.getRef();
 837                 Utf8Entry layout = (Utf8Entry) attr_definition_layout.getRef();
 838                 int       ctype  = (header &  ADH_CONTEXT_MASK);
 839                 int       index  = (header >> ADH_BIT_SHIFT) - ADH_BIT_IS_LSB;
 840                 Attribute.Layout def = new Attribute.Layout(ctype,
 841                                                             name.stringValue(),
 842                                                             layout.stringValue());
 843                 // Check layout string for Java 6 extensions.
 844                 String pvLayout = def.layoutForPackageMajver(getPackageMajver());
 845                 if (!pvLayout.equals(def.layout())) {
 846                     throw new IOException("Bad attribute layout in version 150 archive: "+def.layout());
 847                 }
 848                 this.setAttributeLayoutIndex(def, index);
 849                 if (dump != null)  dump.println(index+" "+def);
 850             }
 851         } // TODO TWR: this relies on new null treatment for TWR's close()
 852         attr_definition_headers.doneDisbursing();
 853         attr_definition_name.doneDisbursing();
 854         attr_definition_layout.doneDisbursing();
 855         // Attribute layouts define bands, one per layout element.
 856         // Create them now, all at once.
 857         makeNewAttributeBands();
 858         attr_definition_bands.doneDisbursing();
 859     }
 860 
 861     void readInnerClasses() throws IOException {
 862         //  ic_bands:
 863         //        *ic_this_class :UDELTA5  (cp_Class)
 864         //        *ic_flags :UNSIGNED5
 865         //        *ic_outer_class :DELTA5  (null or cp_Class)
 866         //        *ic_name :DELTA5  (null or cp_Utf8)
 867         ic_this_class.expectLength(numInnerClasses);
 868         ic_this_class.readFrom(in);
 869         ic_flags.expectLength(numInnerClasses);
 870         ic_flags.readFrom(in);
 871         int longICCount = 0;