【问题标题】:Camel: GenericFileFilter and Recursive not working togetherCamel:GenericFileFilter 和 Recursive 不能一起工作
【发布时间】:2020-03-14 07:06:26
【问题描述】:

我正在尝试使用 camel 从 FTP 服务器下载多个文件。

我正在使用 recursive=true 选项和 include=..xlsx|..xlsm 选项。

我的端点如下所示:

from(FTP_OPTION + "?include=.*.xlsx|.*.xlsm&recursive=true")
.to(ANOTHER_ENDPOINT);

这工作正常,但现在我需要一个更强大的过滤器,所以我使用 GenericFileFilter

我的过滤器如下所示:

public class MyFilter <T> implements GenericFileFilter<T>{
    @Override
    public boolean accept(GenericFile<T> file) {    
        String name = file.getFileName();
        final String regex = "[\\w,\\s-ñÑ]+\\.(xlsx|xlsm)";
        return name.matches(regex);
    }
}

我的新端点是这样的:

from(FTP_OPTION + "?filter=#myFilter&recursive=true")
.to(ANOTHER_ENDPOINT);

问题是当我使用这个端点时,只从根级别获取文件,而不是在子目录中查找文件。

过滤器和递归之间是否存在某种不兼容?还是我错过了其他选择?

谢谢!

【问题讨论】:

    标签: java apache-camel integration


    【解决方案1】:

    AFAIR 通用过滤器也用于目录,因此您需要检查这一点并为接受哪些目录返回 true。有一个isDirectory 方法可以用来知道,如果你只想要所有的目录,那么返回true。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-07
      • 2019-08-17
      • 2016-11-23
      • 2019-02-18
      • 2015-05-16
      • 2017-10-14
      • 2012-06-01
      • 2011-11-05
      相关资源
      最近更新 更多