java 如何使用 Camel 组件 File2 中的包含参数按扩展名过滤文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15060077/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 18:21:19  来源:igfitidea点击:

How to filter files by extensions using include parameter in Camel component File2

javafileapache-camel

提问by Dmitrii Borovoi

I need the simplest filter by extension: f.e. file 20120523.173227.CustomerMaster05092012.QWERTY.xml route:

我需要最简单的按扩展名过滤:fe 文件 20120523.173227.CustomerMaster05092012.QWERTY.xml 路由:

<from uri="file://{{fdr.folder.working.url}}&amp;include=*.xml"/>

doesn't work:

不起作用:

Dangling meta character '*' near index 0

索引 0 附近的悬空元字符“*”

WARN - file://root_folder/working/) [FileConsumer] Consumer Consumer[file://root_folder/working/?delay=1000&delete=true&idempotent=false&include=*.xml&initialDelay=1000&readLock=changed] failed polling endpoint: Endpoint[file://root_folder/working/?delay=1000&delete=true&idempotent=false&include=*.xml&initialDelay=1000&readLock=changed]. Will try again at next poll. Caused by: [java.util.regex.PatternSyntaxException - Dangling meta character '*' near index 0
*.xml
^]
java.util.regex.PatternSyntaxException: Dangling meta character '*' near index 0
*.xml
^
    at java.util.regex.Pattern.error(Pattern.java:1713)
    at java.util.regex.Pattern.sequence(Pattern.java:1878)
    at java.util.regex.Pattern.expr(Pattern.java:1752)
    at java.util.regex.Pattern.compile(Pattern.java:1460)
    at java.util.regex.Pattern.<init>(Pattern.java:1133)
    at java.util.regex.Pattern.compile(Pattern.java:823)
    at java.util.regex.Pattern.matches(Pattern.java:928)
    at java.lang.String.matches(String.java:2090)
    at org.apache.camel.component.file.GenericFileConsumer.isMatched(GenericFileConsumer.java:458)
    at org.apache.camel.component.file.GenericFileConsumer.isValidFile(GenericFileConsumer.java:395)
    at org.apache.camel.component.file.FileConsumer.pollDirectory(FileConsumer.java:94)
    at org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:107)
    at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:142)
    at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:92)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
    at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access1(ScheduledThreadPoolExecutor.java:98)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:180)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:204)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)

ok maybe my bad. I put whole file to include:

好吧,也许我不好。我把整个文件包括在内:

<from uri="file://{{fdr.folder.working.url}}&amp;include=20120523.173227.CustomerMaster05092012.QWERTY.xml"/>

Whole file is OK. Let's try put * in the middle of file name

整个文件没问题。让我们试着把 * 放在文件名的中间

<from uri="file://{{fdr.folder.working.url}}&amp;include=20120523.*.xml"/>

and again it is OK. Let's put only one digit in file name

再一次没问题。让我们在文件名中只输入一位

<from uri="file://{{fdr.folder.working.url}}&amp;include=2*.xml"/>

noup, camel didn't find such files I tried escaped asterisk but it did't help.

noup,camel 没有找到这样的文件,我尝试转义星号,但没有帮助。

<from uri="file://{{fdr.folder.working.url}}&amp;include=\*.xml"/>
and
<from uri="file://{{fdr.folder.working.url}}&amp;include=\*.xml"/>

File was just ignored. so question 1: how to use asterisk?

文件只是被忽略了。所以问题1:如何使用星号?

and question 2: how to use multimple file extensions, like include=.xml;.zip

和问题 2:如何使用多个文件扩展名,例如 include= .xml; 。压缩

thks

谢谢

回答by Dmitrii Borovoi

damn, good thinking comes after, using brute force I found out correct value for include:

该死的,好的想法随之而来,使用蛮力我发现正确的价值包括:

.*.xml|.*.zip

回答by Simon

(?i).*.xml|.*.zip

If you want case insensitive file extension matching.

如果您想要不区分大小写的文件扩展名匹配。

回答by Adam Boczek

You have to properly escape the backslash in string and use end of string sign '$': include=.*\\.xml$

您必须正确转义字符串中的反斜杠并使用字符串结尾符号“$”:include=.*\\.xml$