[jboss-cvs] JBoss Profiler SVN: r467 - branches/JBossProfiler2/src/main/org/jboss/profiler/agent.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Aug 16 07:22:11 EDT 2008


Author: jesper.pedersen
Date: 2008-08-16 07:22:11 -0400 (Sat, 16 Aug 2008)
New Revision: 467

Modified:
   branches/JBossProfiler2/src/main/org/jboss/profiler/agent/ClassRepository.java
   branches/JBossProfiler2/src/main/org/jboss/profiler/agent/JavassistTransformer.java
Log:
Alway close streams

Modified: branches/JBossProfiler2/src/main/org/jboss/profiler/agent/ClassRepository.java
===================================================================
--- branches/JBossProfiler2/src/main/org/jboss/profiler/agent/ClassRepository.java	2008-08-16 11:21:49 UTC (rev 466)
+++ branches/JBossProfiler2/src/main/org/jboss/profiler/agent/ClassRepository.java	2008-08-16 11:22:11 UTC (rev 467)
@@ -58,15 +58,25 @@
       File file = getFile(name, loader);
       
       if (file.exists()) {
-        byte[] buffer = new byte[(int)file.length()];
+        FileInputStream fis = null;
+        try {
+          byte[] buffer = new byte[(int)file.length()];
         
-        FileInputStream fis = new FileInputStream(file);
-        BufferedInputStream bis = new BufferedInputStream(fis, 16384);
+          fis = new FileInputStream(file);
+          BufferedInputStream bis = new BufferedInputStream(fis, 16384);
         
-        bis.read(buffer);
-        bis.close();
-        
-        return buffer;
+          bis.read(buffer);
+
+          return buffer;
+        } finally {
+          if (fis != null) {
+            try {
+              fis.close();
+            } catch (IOException ioe) {
+              // Ignore
+            }
+          }
+        }
       }
       
       return null;
@@ -84,13 +94,23 @@
     synchronized (lock) {
       File file = getFile(name, loader);
 
-      FileOutputStream fos = new FileOutputStream(file);
-      BufferedOutputStream bos = new BufferedOutputStream(fos, 16384);
-      
-      bos.write(clz);
-      
-      bos.flush();
-      bos.close();
+      FileOutputStream fos = null;
+      try {
+        fos = new FileOutputStream(file);
+        BufferedOutputStream bos = new BufferedOutputStream(fos, 16384);
+        
+        bos.write(clz);
+        
+        bos.flush();
+      } finally {
+        if (fos != null) {
+          try {
+            fos.close();
+          } catch (IOException ioe) {
+            // Ignore
+          }
+        }
+      }
     }
   }
 

Modified: branches/JBossProfiler2/src/main/org/jboss/profiler/agent/JavassistTransformer.java
===================================================================
--- branches/JBossProfiler2/src/main/org/jboss/profiler/agent/JavassistTransformer.java	2008-08-16 11:21:49 UTC (rev 466)
+++ branches/JBossProfiler2/src/main/org/jboss/profiler/agent/JavassistTransformer.java	2008-08-16 11:22:11 UTC (rev 467)
@@ -53,9 +53,10 @@
    * @exception IOException If an error occurs
    */
   protected byte[] generateInstrumented(String className, byte[] ob) throws IOException {
+    ByteArrayInputStream bis = null;
     try {
       ClassPool pool = ClassPool.getDefault();
-      ByteArrayInputStream bis = new ByteArrayInputStream(ob);
+      bis = new ByteArrayInputStream(ob);
       
       CtClass cc = pool.makeClass(bis);
       CtConstructor[] constructors =  cc.getDeclaredConstructors();
@@ -76,6 +77,14 @@
       IOException ioe = new IOException(e.getMessage());
       ioe.initCause(e);
       throw ioe;
+    } finally {
+      if (bis != null) {
+        try {
+          bis.close();
+        } catch (IOException ioe) {
+          // Ignore
+        }
+      }
     }
   }
 




More information about the jboss-cvs-commits mailing list