cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r629489 - in /incubator/cxf/branches/2.0.x-fixes: ./ api/src/main/java/org/apache/cxf/io/CachedOutputStream.java common/common/src/main/java/org/apache/cxf/helpers/FileUtils.java
Date Wed, 20 Feb 2008 15:01:00 GMT
Author: dkulp
Date: Wed Feb 20 07:00:59 2008
New Revision: 629489

URL: http://svn.apache.org/viewvc?rev=629489&view=rev
Log:
Merged revisions 629480 via svnmerge from 
https://svn.apache.org/repos/asf/incubator/cxf/trunk

........
  r629480 | dkulp | 2008-02-20 09:38:01 -0500 (Wed, 20 Feb 2008) | 2 lines
  
  [CXF-1408, CXF-1438] Make sure the tmp dir exists each time, make sure temp files are deleted
........

Modified:
    incubator/cxf/branches/2.0.x-fixes/   (props changed)
    incubator/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java
    incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/FileUtils.java

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

Modified: incubator/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java?rev=629489&r1=629488&r2=629489&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java
(original)
+++ incubator/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java
Wed Feb 20 07:00:59 2008
@@ -77,6 +77,8 @@
     private File outputDir = DEFAULT_TEMP_DIR;
 
     private List<CachedOutputStreamCallback> callbacks;
+    
+    private List<Object> streamList = new ArrayList<Object>();
 
     public CachedOutputStream(PipedInputStream stream) throws IOException {
         currentStream = new PipedOutputStream(stream);
@@ -153,9 +155,8 @@
         
         doClose();
         currentStream.close();
-        dispose();
+        maybeDeleteTempFile(currentStream);
         postClose();
-        
     }
 
     public boolean equals(Object obj) {
@@ -367,6 +368,7 @@
         currentStream = new BufferedOutputStream(new FileOutputStream(tempFile));
         bout.writeTo(currentStream);
         inmem = false;
+        streamList.add(currentStream);
     }
 
     public File getTempFile() {
@@ -387,34 +389,33 @@
             }
         } else {
             try {
-                return new FileInputStream(tempFile) {
+                FileInputStream fileInputStream = new FileInputStream(tempFile) {
                     public void close() throws IOException {
                         super.close();
-                        if (tempFile != null) {
-                            tempFile.delete();
-                            //tempFile = null;
-                        }
-                        currentStream = new ByteArrayOutputStream();
-                        inmem = true;
+                        maybeDeleteTempFile(this);
                     }
                 };
+                streamList.add(fileInputStream);
+                return fileInputStream;
             } catch (FileNotFoundException e) {
                 throw new IOException("Cached file was deleted, " + e.toString());
             }
         }
     }
-
-    public void dispose() {
-        if (!inmem && tempFile != null) {
+    
+    private void maybeDeleteTempFile(Object stream) {
+        streamList.remove(stream);
+        if (!inmem && tempFile != null && streamList.isEmpty()) {
             tempFile.delete();
-            //tempFile = null;
+            tempFile = null;
+            currentStream = new LoadingByteArrayOutputStream(1024);
+            inmem = true;
         }
     }
 
     public void setOutputDir(File outputDir) throws IOException {
         this.outputDir = outputDir;
     }
-
     public void setThreshold(long threshold) {
         this.threshold = threshold;
     }

Modified: incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/FileUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/FileUtils.java?rev=629489&r1=629488&r2=629489&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/FileUtils.java
(original)
+++ incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/FileUtils.java
Wed Feb 20 07:00:59 2008
@@ -41,7 +41,8 @@
     }
     
     private static synchronized File getDefaultTempDir() {
-        if (defaultTempDir != null) {
+        if (defaultTempDir != null
+            && defaultTempDir.exists()) {
             return defaultTempDir;
         }
         



Mime
View raw message