骆驼:“文件"组件,但仅将文件名作为正文传递 [英] Camel: "file" component, but only pass file name as body

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

问题描述

我正在尝试使用 Camel 处理潜在的大文件,并且担心它们适合"在 Camel Message 的正文中.有没有一种方法可以将文件的名称(路径)作为消息正文传递,然后在处理器中使用它从磁盘读取?

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 实例.这本质上是 Camel 文件组件自己做的事情(尽管它被放置在 WrappedFile 中,因为与 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天全站免登陆