You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2011/09/22 15:25:29 UTC

svn commit: r1174119 - in /camel/branches/camel-2.7.x/camel-core/src: main/java/org/apache/camel/component/file/GenericFileConverter.java test/java/org/apache/camel/component/file/GenericFileConverterTest.java

Author: janstey
Date: Thu Sep 22 13:25:28 2011
New Revision: 1174119

URL: http://svn.apache.org/viewvc?rev=1174119&view=rev
Log:
Manually merged revision 1124595 from trunk.

CAMEL-3962: java.io.File -> InputStream converter should favor using FileInputStream instead of loading content into memory.


Modified:
    camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConverter.java   (contents, props changed)
    camel/branches/camel-2.7.x/camel-core/src/test/java/org/apache/camel/component/file/GenericFileConverterTest.java   (contents, props changed)

Modified: camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConverter.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConverter.java?rev=1174119&r1=1174118&r2=1174119&view=diff
==============================================================================
--- camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConverter.java (original)
+++ camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConverter.java Thu Sep 22 13:25:28 2011
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.file;
 
+import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.Serializable;
@@ -63,7 +65,11 @@ public final class GenericFileConverter 
     @Converter
     public static InputStream genericFileToInputStream(GenericFile<?> file, Exchange exchange) throws IOException {
         if (exchange != null) {
-            // ensure the body is loaded as we want the input stream of the body
+            // use a file input stream if its a java.io.File
+            if (file.getFile() instanceof java.io.File) {
+                return new FileInputStream((File) file.getFile());
+            }
+            // otherwise ensure the body is loaded as we want the input stream of the body
             file.getBinding().loadContent(exchange, file);
             return exchange.getContext().getTypeConverter().convertTo(InputStream.class, exchange, file.getBody());
         } else {

Propchange: camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConverter.java
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Thu Sep 22 13:25:28 2011
@@ -0,0 +1 @@
+/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConverter.java:1124595

Modified: camel/branches/camel-2.7.x/camel-core/src/test/java/org/apache/camel/component/file/GenericFileConverterTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.7.x/camel-core/src/test/java/org/apache/camel/component/file/GenericFileConverterTest.java?rev=1174119&r1=1174118&r2=1174119&view=diff
==============================================================================
--- camel/branches/camel-2.7.x/camel-core/src/test/java/org/apache/camel/component/file/GenericFileConverterTest.java (original)
+++ camel/branches/camel-2.7.x/camel-core/src/test/java/org/apache/camel/component/file/GenericFileConverterTest.java Thu Sep 22 13:25:28 2011
@@ -17,11 +17,13 @@
 package org.apache.camel.component.file;
 
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.InputStream;
 import java.io.Serializable;
 
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 
@@ -145,4 +147,32 @@ public class GenericFileConverterTest ex
         assertMockEndpointsSatisfied();
     }
 
+    public void testToFileInputStream() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("file://target/gf")
+                    .convertBodyTo(InputStream.class)
+                    .process(new Processor() {
+                        @Override
+                        public void process(Exchange exchange) throws Exception {
+                            Object body = exchange.getIn().getBody();
+                            assertIsInstanceOf(FileInputStream.class, body);
+                        }
+                    })
+                    .to("mock:result");
+            }
+        });
+        context.start();
+
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+        mock.message(0).body().isInstanceOf(FileInputStream.class);
+        mock.message(0).body(String.class).isEqualTo("Hello World");
+
+        template.sendBodyAndHeader("file://target/gf", "Hello World", Exchange.FILE_NAME, "hello.txt");
+
+        assertMockEndpointsSatisfied();
+    }
+
 }

Propchange: camel/branches/camel-2.7.x/camel-core/src/test/java/org/apache/camel/component/file/GenericFileConverterTest.java
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Thu Sep 22 13:25:28 2011
@@ -0,0 +1 @@
+/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/GenericFileConverterTest.java:1124595