You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2012/04/11 07:49:51 UTC

svn commit: r1324569 - in /camel/branches/camel-2.9.x: ./ camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java camel-core/src/main/java/org/apache/camel/util/IOHelper.java

Author: davsclaus
Date: Wed Apr 11 05:49:51 2012
New Revision: 1324569

URL: http://svn.apache.org/viewvc?rev=1324569&view=rev
Log:
CAMEL-5136: File component now explicit forces a flush when files have been written.

Modified:
    camel/branches/camel-2.9.x/   (props changed)
    camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java
    camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/util/IOHelper.java

Propchange: camel/branches/camel-2.9.x/
------------------------------------------------------------------------------
  Merged /camel/trunk:r1324568

Propchange: camel/branches/camel-2.9.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java?rev=1324569&r1=1324568&r2=1324569&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java (original)
+++ camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java Wed Apr 11 05:49:51 2012
@@ -257,6 +257,8 @@ public class FileOperations implements G
             }
         } finally {
             IOHelper.close(in, source.getName(), LOG);
+            // force updates to be written, and then close afterwards
+            IOHelper.force(out, target.getName(), LOG);
             IOHelper.close(out, target.getName(), LOG);
         }
     }
@@ -279,6 +281,8 @@ public class FileOperations implements G
             }
         } finally {
             IOHelper.close(in, target.getName(), LOG);
+            // force updates to be written, and then close afterwards
+            IOHelper.force(out, target.getName(), LOG);
             IOHelper.close(out, target.getName(), LOG);
         }
     }

Modified: camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/util/IOHelper.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/util/IOHelper.java?rev=1324569&r1=1324568&r2=1324569&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/util/IOHelper.java (original)
+++ camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/util/IOHelper.java Wed Apr 11 05:49:51 2012
@@ -27,6 +27,7 @@ import java.io.OutputStream;
 import java.io.Reader;
 import java.io.UnsupportedEncodingException;
 import java.io.Writer;
+import java.nio.channels.FileChannel;
 import java.nio.charset.Charset;
 import java.nio.charset.UnsupportedCharsetException;
 
@@ -192,6 +193,28 @@ public final class IOHelper {
     }
 
     /**
+     * Forces any updates to this channel's file to be written to the storage device that contains it.
+     *
+     * @param channel the file channel
+     * @param name the name of the resource
+     * @param log the log to use when reporting closure warnings
+     */
+    public static void force(FileChannel channel, String name, Logger log) {
+        try {
+            channel.force(true);
+        } catch (Exception e) {
+            if (log != null) {
+                if (name != null) {
+                    log.warn("Cannot force FileChannel: " + name + ". Reason: " + e.getMessage(), e);
+                } else {
+                    log.warn("Cannot force FileChannel. Reason: " + e.getMessage(), e);
+                }
+            }
+        }
+
+    }
+
+    /**
      * Closes the given resource if it is available, logging any closing
      * exceptions to the given log
      *