Author: brentworden
Date: Fri Aug 12 21:06:37 2005
New Revision: 232415

URL: http://svn.apache.org/viewcvs?rev=232415&view=rev
Log:
PR 36084: Temp. files were not being deleted because open file streams were not 
being closed properly.

Modified:
    
jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/TestUtils.java

Modified: 
jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/TestUtils.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/TestUtils.java?rev=232415&r1=232414&r2=232415&view=diff
==============================================================================
--- 
jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/TestUtils.java
 (original)
+++ 
jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/TestUtils.java
 Fri Aug 12 21:06:37 2005
@@ -19,6 +19,7 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
+import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 
@@ -74,25 +75,43 @@
         Object result = null;
         
         File tmp = null;
+        FileOutputStream fo = null;
+        FileInputStream fi = null;
         
         try {
-            
             // serialize the Object
             tmp = File.createTempFile("test",".ser");
-            FileOutputStream fo = new FileOutputStream(tmp);
+            fo = new FileOutputStream(tmp);
             ObjectOutputStream so = new ObjectOutputStream(fo);
             so.writeObject(o);
             so.flush();
+            fo.close();
 
             // deserialize the Book
-            FileInputStream fi = new FileInputStream(tmp);
+            fi = new FileInputStream(tmp);
             ObjectInputStream si = new ObjectInputStream(fi);  
             result = si.readObject();
-            
-        }catch (Exception e) {
-            e.printStackTrace();
-        }finally{
-            if(tmp != null) tmp.delete();
+        } catch (Exception ex) {
+               
+        } finally {
+               if (fo != null) {
+                       try {
+                               fo.close();
+                       } catch (IOException ex) {
+                       }
+               }
+
+               if (fi != null) {
+                       try {
+                       fi.close();
+                       } catch (IOException ex) {
+                       }
+               }
+        }
+        
+        
+        if (tmp != null) {
+               tmp.delete();
         }
         
         return result;



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to