cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1342687 - /cxf/trunk/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java
Date Fri, 25 May 2012 15:38:55 GMT
Author: dkulp
Date: Fri May 25 15:38:54 2012
New Revision: 1342687

URL: http://svn.apache.org/viewvc?rev=1342687&view=rev
Log:
[CXF-4342] Put some locking around tempFile deletion and make sure any
issues in creating the tempfile result in it getting cleaned up.

Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java?rev=1342687&r1=1342686&r2=1342687&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java Fri May 25 15:38:54
2012
@@ -246,8 +246,7 @@ public class CachedOutputStream extends 
                     IOUtils.copyAndCloseInput(fin, out);
                 }
                 streamList.remove(currentStream);
-                tempFile.delete();
-                tempFile = null;
+                deleteTempFile();
                 inmem = true;
             }
         }
@@ -445,7 +444,10 @@ public class CachedOutputStream extends 
             //Could be IOException or SecurityException or other issues.
             //Don't care what, just keep it in memory.
             tempFileFailed = true;
-            tempFile = null;
+            if (currentStream != bout) {
+                currentStream.close();
+            }
+            deleteTempFile();
             inmem = true;
             currentStream = bout;
         }
@@ -483,6 +485,13 @@ public class CachedOutputStream extends 
         }
     }
     
+    private synchronized void deleteTempFile() {
+        if (tempFile != null) {
+            File file = tempFile;
+            tempFile = null;
+            FileUtils.delete(file);
+        }
+    }
     private void maybeDeleteTempFile(Object stream) {
         streamList.remove(stream);
         if (!inmem && tempFile != null && streamList.isEmpty() &&
allowDeleteOfFile) {
@@ -494,8 +503,7 @@ public class CachedOutputStream extends 
                     //ignore
                 }
             }
-            tempFile.delete();
-            tempFile = null;
+            deleteTempFile();
             currentStream = new LoadingByteArrayOutputStream(1024);
             inmem = true;
         }



Mime
View raw message