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:48:09 UTC

svn commit: r1342700 - in /cxf/branches/2.3.x-fixes: ./ api/src/main/java/org/apache/cxf/io/CachedOutputStream.java

Author: dkulp
Date: Fri May 25 15:48:08 2012
New Revision: 1342700

URL: http://svn.apache.org/viewvc?rev=1342700&view=rev
Log:
Merged revisions 1342698 via  svn merge from
https://svn.us.apache.org/repos/asf/cxf/branches/2.4.x-fixes

........
  r1342698 | dkulp | 2012-05-25 11:46:14 -0400 (Fri, 25 May 2012) | 18 lines
  
  Merged revisions 1342690 via  svn merge from
  https://svn.apache.org/repos/asf/cxf/branches/2.5.x-fixes
  
  ........
    r1342690 | dkulp | 2012-05-25 11:41:43 -0400 (Fri, 25 May 2012) | 10 lines
    
    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.3.x-fixes/   (props changed)
    cxf/branches/2.3.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java

Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.3.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java?rev=1342700&r1=1342699&r2=1342700&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java (original)
+++ cxf/branches/2.3.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java Fri May 25 15:48:08 2012
@@ -239,8 +239,7 @@ public class CachedOutputStream extends 
                     IOUtils.copyAndCloseInput(fin, out);
                 }
                 streamList.remove(currentStream);
-                tempFile.delete();
-                tempFile = null;
+                deleteTempFile();
                 inmem = true;
             }
         }
@@ -438,7 +437,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;
         }
@@ -476,6 +478,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) {
@@ -487,8 +496,7 @@ public class CachedOutputStream extends 
                     //ignore
                 }
             }
-            tempFile.delete();
-            tempFile = null;
+            deleteTempFile();
             currentStream = new LoadingByteArrayOutputStream(1024);
             inmem = true;
         }