On 8/9/07, Aaron Crickenberger <[EMAIL PROTECTED]> wrote:
> I've been playing around with Camel's FileComponent.  I started with
> camel-example-spring, and modified MyRouteBuilder to look like so:
>
> public class MyRouteBuilder extends RouteBuilder {
>     public void configure() {
>         from("file:/tmp/test/incoming/").to("file:/tmp/test/outgoing/");
>     }
> }
>
> Putting a file in the "incoming" directory then results in this:
>
> org.apache.camel.InvalidTypeException: Could not convert value:
> [EMAIL PROTECTED] to type: java.nio.ByteBuffer but has
> value: [EMAIL PROTECTED] of type:
> java.io.BufferedInputStream on the exchange: Exchange[FileMessage:
> /tmp/test/incoming/foo.lock]

Great catch! :) This was my fault I think; the fix for CAMEL-90 broke
this. Bad James!

I've raised an issue to track this bug fixes release etc...
https://issues.apache.org/activemq/browse/CAMEL-95

[snip]


> Adding the following File to ByteBuffer conversion to NIOConverter does
> the trick:
>
> @Converter
> public static ByteBuffer toByteBuffer(File file) throws IOException {
>     byte[] buf = new byte[(int) file.length()];
>     InputStream in = new BufferedInputStream(new FileInputStream(file));
>     in.read(buf);
>     return ByteBuffer.wrap(buf);
> }
>
> Hope this helps!

Awesome stuff Aaron!

I've added the test case FileConsumerProducerRouteTest which
reproduces this issue (consuming 2 files from a directory to a new
output directory, then polling this output directory and asserting via
Mocks that the right number of messages are received)...
https://svn.apache.org/repos/asf/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerProducerRouteTest.java

Then I've contributed your patch - many thanks!

While reading the code of the FileProducer, I wasn't totally happy
with the implementation; converting a File to a single ByteBuffer by
default; which won't handle massive files very easily; so I've changed
the implementation to just use streams by default (working with 128K
chunks at a time) which will hopefully allow us to deal with huge
files more easily etc.

We could add a further optimisation one day to make FileProcessor be
File-aware and use FileChannel APIs to move an entire file from one
channel to another in a single method call which should be faster.
https://issues.apache.org/activemq/browse/CAMEL-94

Thanks again!

-- 
James
-------
http://macstrac.blogspot.com/

Reply via email to