commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1748463 - in /commons/proper/bcel/trunk/src/test/java/org/apache/bcel: PerformanceTest.java classfile/JDKClassDumpTestCase.java generic/JDKGenericDumpTestCase.java verifier/tests/TestCreator.java
Date Tue, 14 Jun 2016 20:48:10 GMT
Author: ggregory
Date: Tue Jun 14 20:48:09 2016
New Revision: 1748463

URL: http://svn.apache.org/viewvc?rev=1748463&view=rev
Log:
Use try-with-resources.

Modified:
    commons/proper/bcel/trunk/src/test/java/org/apache/bcel/PerformanceTest.java
    commons/proper/bcel/trunk/src/test/java/org/apache/bcel/classfile/JDKClassDumpTestCase.java
    commons/proper/bcel/trunk/src/test/java/org/apache/bcel/generic/JDKGenericDumpTestCase.java
    commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/tests/TestCreator.java

Modified: commons/proper/bcel/trunk/src/test/java/org/apache/bcel/PerformanceTest.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/test/java/org/apache/bcel/PerformanceTest.java?rev=1748463&r1=1748462&r2=1748463&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/test/java/org/apache/bcel/PerformanceTest.java (original)
+++ commons/proper/bcel/trunk/src/test/java/org/apache/bcel/PerformanceTest.java Tue Jun 14
20:48:09 2016
@@ -77,48 +77,46 @@ public final class PerformanceTest exten
         System.out.println("parsing " + lib);
 
         total.start();
-        JarFile jar = new JarFile(lib);
-        Enumeration<?> en = jar.entries();
+        try (JarFile jar = new JarFile(lib)) {
+            Enumeration<?> en = jar.entries();
 
-        while (en.hasMoreElements()) {
-            JarEntry e = (JarEntry) en.nextElement();
-            if (e.getName().endsWith(".class")) {
-                InputStream in = jar.getInputStream(e);
-                byte[] bytes = read(in);
-
-                parseTime.start();
-                JavaClass clazz = new ClassParser(new ByteArrayInputStream(bytes), e.getName())
-                        .parse();
-                parseTime.stop();
-
-                cgenTime.start();
-                ClassGen cg = new ClassGen(clazz);
-                cgenTime.stop();
-
-                Method[] methods = cg.getMethods();
-                for (Method m : methods) {
-                    mgenTime.start();
-                    MethodGen mg = new MethodGen(m, cg.getClassName(), cg.getConstantPool());
-                    InstructionList il = mg.getInstructionList();
-                    mgenTime.stop();
-
-                    mserTime.start();
-                    if (il != null) {
-                        mg.getInstructionList().setPositions();
-                        mg.setMaxLocals();
-                        mg.setMaxStack();
+            while (en.hasMoreElements()) {
+                JarEntry e = (JarEntry) en.nextElement();
+                if (e.getName().endsWith(".class")) {
+                    InputStream in = jar.getInputStream(e);
+                    byte[] bytes = read(in);
+
+                    parseTime.start();
+                    JavaClass clazz = new ClassParser(new ByteArrayInputStream(bytes), e.getName()).parse();
+                    parseTime.stop();
+
+                    cgenTime.start();
+                    ClassGen cg = new ClassGen(clazz);
+                    cgenTime.stop();
+
+                    Method[] methods = cg.getMethods();
+                    for (Method m : methods) {
+                        mgenTime.start();
+                        MethodGen mg = new MethodGen(m, cg.getClassName(), cg.getConstantPool());
+                        InstructionList il = mg.getInstructionList();
+                        mgenTime.stop();
+
+                        mserTime.start();
+                        if (il != null) {
+                            mg.getInstructionList().setPositions();
+                            mg.setMaxLocals();
+                            mg.setMaxStack();
+                        }
+                        cg.replaceMethod(m, mg.getMethod());
+                        mserTime.stop();
                     }
-                    cg.replaceMethod(m, mg.getMethod());
-                    mserTime.stop();
-                }
 
-                serTime.start();
-                cg.getJavaClass().getBytes();
-                serTime.stop();
+                    serTime.start();
+                    cg.getJavaClass().getBytes();
+                    serTime.stop();
+                }
             }
         }
-
-        jar.close();
         total.stop();
         if (REPORT) {
             System.out.println("ClassParser.parse: " + parseTime);

Modified: commons/proper/bcel/trunk/src/test/java/org/apache/bcel/classfile/JDKClassDumpTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/test/java/org/apache/bcel/classfile/JDKClassDumpTestCase.java?rev=1748463&r1=1748462&r2=1748463&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/test/java/org/apache/bcel/classfile/JDKClassDumpTestCase.java
(original)
+++ commons/proper/bcel/trunk/src/test/java/org/apache/bcel/classfile/JDKClassDumpTestCase.java
Tue Jun 14 20:48:09 2016
@@ -44,7 +44,7 @@ public class JDKClassDumpTestCase {
 
             @Override
             public boolean accept(final File file) {
-                if(file.getName().endsWith(".jar")) {
+                if (file.getName().endsWith(".jar")) {
                     try {
                         testJar(file);
                     } catch (Exception e) {
@@ -59,21 +59,21 @@ public class JDKClassDumpTestCase {
 
     private void testJar(final File file) throws Exception {
         System.out.println("parsing " + file);
-        JarFile jar = new JarFile(file);
-        Enumeration<JarEntry> en = jar.entries();
-
-        while (en.hasMoreElements()) {
-            JarEntry e = en.nextElement();
-            final String name = e.getName();
-            if (name.endsWith(".class")) {
-//                System.out.println("parsing " + name);
-                InputStream in = jar.getInputStream(e);
-                ClassParser parser = new ClassParser(in, name);
-                JavaClass jc = parser.parse();
-                compare(jc, jar.getInputStream(e), name);
+        try (JarFile jar = new JarFile(file)) {
+            Enumeration<JarEntry> en = jar.entries();
+            while (en.hasMoreElements()) {
+                JarEntry e = en.nextElement();
+                final String name = e.getName();
+                if (name.endsWith(".class")) {
+                    // System.out.println("parsing " + name);
+                    try (InputStream in = jar.getInputStream(e)) {
+                        ClassParser parser = new ClassParser(in, name);
+                        JavaClass jc = parser.parse();
+                        compare(jc, jar.getInputStream(e), name);
+                    }
+                }
             }
         }
-        jar.close();
     }
 
     private void compare(final JavaClass jc, final InputStream inputStream, final String
name) throws Exception {

Modified: commons/proper/bcel/trunk/src/test/java/org/apache/bcel/generic/JDKGenericDumpTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/test/java/org/apache/bcel/generic/JDKGenericDumpTestCase.java?rev=1748463&r1=1748462&r2=1748463&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/test/java/org/apache/bcel/generic/JDKGenericDumpTestCase.java
(original)
+++ commons/proper/bcel/trunk/src/test/java/org/apache/bcel/generic/JDKGenericDumpTestCase.java
Tue Jun 14 20:48:09 2016
@@ -50,23 +50,23 @@ public class JDKGenericDumpTestCase {
 
     private void testJar(final File file) throws Exception {
         System.out.println(file);
-        JarFile jar = new JarFile(file);
-        Enumeration<JarEntry> en = jar.entries();
-
-        while (en.hasMoreElements()) {
-            JarEntry e = en.nextElement();
-            final String name = e.getName();
-            if (name.endsWith(".class")) {
-//                System.out.println("- " + name);
-                InputStream in = jar.getInputStream(e);
-                ClassParser parser = new ClassParser(in, name);
-                JavaClass jc = parser.parse();
-                for(Method m : jc.getMethods()) {
-                    compare(name, m);
+        try (JarFile jar = new JarFile(file)) {
+            Enumeration<JarEntry> en = jar.entries();
+            while (en.hasMoreElements()) {
+                JarEntry e = en.nextElement();
+                final String name = e.getName();
+                if (name.endsWith(".class")) {
+                    // System.out.println("- " + name);
+                    try (InputStream in = jar.getInputStream(e)) {
+                        ClassParser parser = new ClassParser(in, name);
+                        JavaClass jc = parser.parse();
+                        for (Method m : jc.getMethods()) {
+                            compare(name, m);
+                        }
+                    }
                 }
             }
         }
-        jar.close();
     }
 
     private void compare(final String name, final Method m) {

Modified: commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/tests/TestCreator.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/tests/TestCreator.java?rev=1748463&r1=1748462&r2=1748463&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/tests/TestCreator.java
(original)
+++ commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/tests/TestCreator.java
Tue Jun 14 20:48:09 2016
@@ -30,13 +30,9 @@ public abstract class TestCreator {
 
     public void create() throws IOException {
         File classFile = new File(getPackageFolder(), getClassName());
-        FileOutputStream out = new FileOutputStream(classFile);
-        try {
+        try (FileOutputStream out = new FileOutputStream(classFile)) {
             create(out);
         }
-        finally {
-            out.close();
-        }
     }
     
     private String getClassName() {



Mime
View raw message