camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r807874 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/converter/stream/CachedOutputStream.java test/java/org/apache/camel/converter/stream/CachedOutputStreamTest.java
Date Wed, 26 Aug 2009 04:25:28 GMT
Author: ningjiang
Date: Wed Aug 26 04:25:27 2009
New Revision: 807874

URL: http://svn.apache.org/viewvc?rev=807874&view=rev
Log:
CAMEL-1934 Fixed the StreamCache Unit test failure on Windows

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/converter/stream/CachedOutputStreamTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java?rev=807874&r1=807873&r2=807874&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java
Wed Aug 26 04:25:27 2009
@@ -25,6 +25,8 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.StreamCache;
@@ -51,6 +53,8 @@
     private boolean inMemory = true;
     private int totalLength;
     private File tempFile;
+    
+    private List<FileInputStreamCache> fileInputStreamCaches = new ArrayList<FileInputStreamCache>(4);
 
     private long threshold = 64 * 1024;
     private File outputDir;
@@ -70,10 +74,13 @@
             @Override
             public void onDone(Exchange exchange) {
                 try {
+                    // close the stream and FileInputStreamCache
+                    close();
+                    for (FileInputStreamCache cache : fileInputStreamCaches) {
+                        cache.close();
+                    }
                     // cleanup temporary file
                     if (tempFile != null) {
-                        // close the stream first and than delete the file
-                        close();
                         boolean deleted = tempFile.delete();
                         if (!deleted) {
                             LOG.warn("Cannot delete temporary cache file: " + tempFile);
@@ -149,7 +156,9 @@
             }
         } else {
             try {
-                return new FileInputStreamCache(tempFile, this);
+                FileInputStreamCache answer = new FileInputStreamCache(tempFile, this);
+                fileInputStreamCaches.add(answer);
+                return answer;
             } catch (FileNotFoundException e) {
                 throw IOHelper.createIOException("Cached file " + tempFile + " not found",
e);
             }
@@ -168,7 +177,9 @@
             }
         } else {
             try {
-                return new FileInputStreamCache(tempFile, this);
+                FileInputStreamCache answer = new FileInputStreamCache(tempFile, this);
+                fileInputStreamCaches.add(answer);
+                return answer;
             } catch (FileNotFoundException e) {
                 throw IOHelper.createIOException("Cached file " + tempFile + " not found",
e);
             }

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/converter/stream/CachedOutputStreamTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/stream/CachedOutputStreamTest.java?rev=807874&r1=807873&r2=807874&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/converter/stream/CachedOutputStreamTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/converter/stream/CachedOutputStreamTest.java
Wed Aug 26 04:25:27 2009
@@ -109,10 +109,7 @@
         cache.reset();
         temp = toString((InputStream)cache);
         assertEquals("Cached a wrong file", temp, TEST_STRING);
-        // windows can't delet the file which is open , so we close the stream first
-        if (System.getProperty("os.name").startsWith("Windows")) {
-            ((InputStream)cache).close();
-        }
+        
         exchange.getUnitOfWork().done(exchange);
         ((InputStream)cache).close();
         



Mime
View raw message