commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1748102 - in /commons/proper/bcel/trunk/src/main/java/org/apache/bcel: classfile/Utility.java util/CodeHTML.java
Date Mon, 13 Jun 2016 07:21:31 GMT
Author: ggregory
Date: Mon Jun 13 07:21:31 2016
New Revision: 1748102

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

Modified:
    commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Utility.java
    commons/proper/bcel/trunk/src/main/java/org/apache/bcel/util/CodeHTML.java

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Utility.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Utility.java?rev=1748102&r1=1748101&r2=1748102&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Utility.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Utility.java Mon Jun
13 07:21:31 2016
@@ -147,16 +147,14 @@ public abstract class Utility {
     public static String codeToString( final byte[] code, final ConstantPool constant_pool,
final int index,
             final int length, final boolean verbose ) {
         StringBuilder buf = new StringBuilder(code.length * 20); // Should be sufficient
// CHECKSTYLE IGNORE MagicNumber
-        ByteSequence stream = new ByteSequence(code);
-        try {
+        try (ByteSequence stream = new ByteSequence(code)) {
             for (int i = 0; i < index; i++) {
                 codeToString(stream, constant_pool, verbose);
             }
             for (int i = 0; stream.available() > 0; i++) {
                 if ((length < 0) || (i < length)) {
                     String indices = fillup(stream.getIndex() + ":", 6, true, ' ');
-                    buf.append(indices).append(codeToString(stream, constant_pool, verbose))
-                            .append('\n');
+                    buf.append(indices).append(codeToString(stream, constant_pool, verbose)).append('\n');
                 }
             }
         } catch (IOException e) {
@@ -1276,12 +1274,12 @@ public abstract class Utility {
             bytes = baos.toByteArray();
         }
         CharArrayWriter caw = new CharArrayWriter();
-        JavaWriter jw = new JavaWriter(caw);
-        for (byte b : bytes) {
-            int in = b & 0x000000ff; // Normalize to unsigned
-            jw.write(in);
+        try (JavaWriter jw = new JavaWriter(caw)) {
+            for (byte b : bytes) {
+                int in = b & 0x000000ff; // Normalize to unsigned
+                jw.write(in);
+            }
         }
-        jw.close();
         return caw.toString();
     }
 

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/util/CodeHTML.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/util/CodeHTML.java?rev=1748102&r1=1748101&r2=1748102&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/util/CodeHTML.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/util/CodeHTML.java Mon Jun 13
07:21:31 2016
@@ -549,32 +549,31 @@ final class CodeHTML {
         if (code != null) { // No code, an abstract method, e.g.
             //System.out.println(name + "\n" + Utility.codeToString(code, constant_pool,
0, -1));
             // Print the byte code
-            ByteSequence stream = new ByteSequence(code);
-            stream.mark(stream.available());
-            findGotos(stream, c);
-            stream.reset();
-            file.println("<TABLE BORDER=0><TR><TH ALIGN=LEFT>Byte<BR>offset</TH>"
-                    + "<TH ALIGN=LEFT>Instruction</TH><TH ALIGN=LEFT>Argument</TH>");
-            for (; stream.available() > 0;) {
-                int offset = stream.getIndex();
-                String str = codeToHTML(stream, method_number);
-                String anchor = "";
-                /* Set an anchor mark if this line is targetted by a goto, jsr, etc.
-                 * Defining an anchor for every line is very inefficient!
-                 */
-                if (goto_set.get(offset)) {
-                    anchor = "<A NAME=code" + method_number + "@" + offset + "></A>";
+            try (ByteSequence stream = new ByteSequence(code)) {
+                stream.mark(stream.available());
+                findGotos(stream, c);
+                stream.reset();
+                file.println("<TABLE BORDER=0><TR><TH ALIGN=LEFT>Byte<BR>offset</TH>"
+                        + "<TH ALIGN=LEFT>Instruction</TH><TH ALIGN=LEFT>Argument</TH>");
+                for (; stream.available() > 0;) {
+                    int offset = stream.getIndex();
+                    String str = codeToHTML(stream, method_number);
+                    String anchor = "";
+                    /*
+                     * Set an anchor mark if this line is targetted by a goto, jsr, etc.
Defining an anchor for every
+                     * line is very inefficient!
+                     */
+                    if (goto_set.get(offset)) {
+                        anchor = "<A NAME=code" + method_number + "@" + offset + "></A>";
+                    }
+                    String anchor2;
+                    if (stream.getIndex() == code.length) {
+                        anchor2 = "<A NAME=code" + method_number + "@" + code.length +
">" + offset + "</A>";
+                    } else {
+                        anchor2 = "" + offset;
+                    }
+                    file.println("<TR VALIGN=TOP><TD>" + anchor2 + "</TD><TD>"
+ anchor + str + "</TR>");
                 }
-                String anchor2;
-                if (stream.getIndex() == code.length) {
-                    anchor2 = "<A NAME=code" + method_number + "@" + code.length + ">"
+ offset
-                            + "</A>";
-                } else {
-                    anchor2 = "" + offset;
-                }
-                file
-                        .println("<TR VALIGN=TOP><TD>" + anchor2 + "</TD><TD>"
+ anchor + str
-                                + "</TR>");
             }
             // Mark last line, may be targetted from Attributes window
             file.println("<TR><TD> </A></TD></TR>");



Mime
View raw message