骆驼:"文件"组成部分,但只传递文件名作为体 [英] Camel: "file" component, but only pass file name as body

查看:107
本文介绍了骆驼:"文件"组成部分,但只传递文件名作为体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图过程中使用骆驼可能很大的文件,并在骆驼消息的身体很担心他们的装修。有没有一种方法我可以只传递文件作为邮件的正文的名称(路径),然后在处理器使用的是从磁盘读取?

I'm trying to process potentially large files using Camel, and am worried about them "fitting" in the body of a Camel Message. Is there a way I can just pass the name (path) of the file as the body of the message, and then in a processor use that to read from disk?

推荐答案

您可以只传递一个java.io.File中的实例。实际上,这就是骆驼文件组件本身做(尽管它放在WrappedFile,由于共享code与FTP组件内)。

You can just pass in a java.io.File instance. This is essentially what the Camel file component does itself (although its placed inside a WrappedFile, due sharing code with the ftp components).

您当然也可以只存储文件作为字符串的名称,然后从处理器访问的文件,无论是通过

You can of course also just store the name of the file as a String, and then from the processor access the file, either by

String name = exchange.getIn().getBody(String.class);
File file = new File(name);
...
FileInputStream fis = new FileInputStream(file);
// read the file from the stream, etc.

这篇关于骆驼:"文件"组成部分,但只传递文件名作为体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆