You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2012/05/25 17:41:43 UTC

svn commit: r1342690 - /cxf/branches/2.5.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java

Author: dkulp
Date: Fri May 25 15:41:43 2012
New Revision: 1342690

URL: http://svn.apache.org/viewvc?rev=1342690&view=rev
Log:
Merged revisions 1342687 via  git cherry-pick from
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1342687 | dkulp | 2012-05-25 11:38:54 -0400 (Fri, 25 May 2012) | 3 lines

  [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/branches/2.5.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java

Modified: cxf/branches/2.5.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java?rev=1342690&r1=1342689&r2=1342690&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java (original)
+++ cxf/branches/2.5.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java Fri May 25 15:41:43 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;
         }