test/java/lang/instrument/ilib/Inject.java

Print this page
rev 3509 : 7021209: convert lang, math, util to use try-with-resources
Reviewed-by: XXX

@@ -116,13 +116,14 @@
         public void reinit(int tracker) {
             this.tracker = tracker;
         }
 
         void dump(File outDir, String filename) throws IOException {
-            FileOutputStream fileOut = new FileOutputStream(new File(outDir, filename));
-            DataOutputStream dataOut = new DataOutputStream(fileOut);
-
+            try (FileOutputStream fileOut =
+                     new FileOutputStream(new File(outDir, filename));
+                 DataOutputStream dataOut = new DataOutputStream(fileOut))
+            {
             String currentClassName = null;
 
             dataOut.writeInt(infoList.size());
             for (Iterator<Info> it = infoList.iterator(); it.hasNext(); ) {
                 Info info = it.next();

@@ -132,11 +133,11 @@
                     dataOut.writeUTF(currentClassName);
                 }
                 dataOut.writeInt(info.location);
                 dataOut.writeUTF(info.methodName);
             }
-            dataOut.close();
+            }
         }
 
         public byte[] bytecodes(String className, String methodName, int location) {
             byte[] injection = new byte[6];
             int injectedIndex = options.fixedIndex != 0? options.fixedIndex : ++counter;