]> source.dussan.org Git - javassist.git/commitdiff
enforced close() in a finally block.
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>
Wed, 9 Jul 2003 08:17:32 +0000 (08:17 +0000)
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>
Wed, 9 Jul 2003 08:17:32 +0000 (08:17 +0000)
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@28 30ef5769-5b8d-40dd-aea6-55b5d6557bb3

src/main/javassist/ClassPool.java
src/main/javassist/ClassPoolTail.java
src/main/javassist/URLClassPath.java

index 837889536f22c8dc69f648bd4787b6ef16414df7..613147772a5ea20a7f11d82f0e96ed6b23a0f53f 100644 (file)
@@ -418,8 +418,13 @@ public class ClassPool {
     {
         ByteArrayOutputStream barray = new ByteArrayOutputStream();
         DataOutputStream out = new DataOutputStream(barray);
-        write(classname, out, true);
-        out.close();
+        try {
+            write(classname, out, true);
+        }
+        finally {
+            out.close();
+        }
+
         return barray.toByteArray();
     }
 
index 678badd213db8192d638c68d55dce09f28676db4..0756cf44c0e8ac6ed13ac198f6dee84b3ffcd055 100644 (file)
@@ -256,8 +256,14 @@ final class ClassPoolTail extends ClassPool {
         throws NotFoundException, IOException
     {
         InputStream fin = openClassfile(classname);
-        byte[] b = readStream(fin);
-        fin.close();
+        byte[] b;
+        try {
+            b = readStream(fin);
+        }
+        finally {
+            fin.close();
+        }
+
         return b;
     }
 
index 9d56635b277db887d72da185411ddcff6caf7f67..279b20f12de0f248b3d2de8d72ec69d137cf9133 100644 (file)
@@ -98,23 +98,26 @@ public class URLClassPath implements ClassPath {
                 directory + classname.replace('.', '/') + ".class");
         int size = con.getContentLength();
         InputStream s = con.getInputStream();
-        if (size <= 0)
-            b = ClassPoolTail.readStream(s);
-        else {
-            b = new byte[size];
-            int len = 0;
-            do {
-                int n = s.read(b, len, size - len);
-                if (n < 0) {
-                    s.close();
-                    throw new IOException("the stream was closed: "
-                                          + classname);
-                }
-                len += n;
-            } while (len < size);
+        try {
+            if (size <= 0)
+                b = ClassPoolTail.readStream(s);
+            else {
+                b = new byte[size];
+                int len = 0;
+                do {
+                    int n = s.read(b, len, size - len);
+                    if (n < 0)
+                        throw new IOException("the stream was closed: "
+                                              + classname);
+
+                    len += n;
+                } while (len < size);
+            }
+        }
+        finally {
+            s.close();
         }
 
-        s.close();
         return b;
     }