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

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

@@ -456,13 +456,13 @@
             Entry[] cpMap = index.cpMap;
             if (verbose > 0)
                 Utils.log.info("Writing "+cpMap.length+" "+ConstantPool.tagName(tag)+" entries...");
 
             if (optDumpBands) {
-                PrintStream ps = new PrintStream(getDumpStream(index, ".idx"));
+                try (PrintStream ps = new PrintStream(getDumpStream(index, ".idx"))) {
                 printArrayTo(ps, cpMap, 0, cpMap.length);
-                ps.close();
+                }
             }
 
             switch (tag) {
             case CONSTANT_Utf8:
                 writeUtf8Bands(cpMap);

@@ -921,12 +921,13 @@
                 assert(ind1 != null);
                 return ((Comparable)ind0).compareTo(ind1);
             }
         });
         attrDefsWritten = new Attribute.Layout[numAttrDefs];
-        PrintStream dump = !optDumpBands ? null
-            : new PrintStream(getDumpStream(attr_definition_headers, ".def"));
+        try (PrintStream dump = !optDumpBands ? null
+                 : new PrintStream(getDumpStream(attr_definition_headers, ".def")))
+        {
         int[] indexForDebug = Arrays.copyOf(attrIndexLimit, ATTR_CONTEXT_LIMIT);
         for (int i = 0; i < defs.length; i++) {
             int header = ((Integer)defs[i][0]).intValue();
             Attribute.Layout def = (Attribute.Layout) defs[i][1];
             attrDefsWritten[i] = def;

@@ -947,11 +948,11 @@
             if (dump != null) {
                 int index = (header >> ADH_BIT_SHIFT) - ADH_BIT_IS_LSB;
                 dump.println(index+" "+def);
             }
         }
-        if (dump != null)  dump.close();
+        } // TODO TWR: relies on new null handling behavior of TWR close()
     }
 
     void writeAttrCounts() throws IOException {
         // Write the four xxx_attr_calls bands.
         for (int ctype = 0; ctype < ATTR_CONTEXT_LIMIT; ctype++) {