gpt4 book ai didi

java - Spring 集成 LastModifiedFileListFilter 不起作用

转载 作者:行者123 更新时间:2023-11-30 06:26:12 31 4
gpt4 key购买 nike

我正在尝试从目录中读取一些文件,并且在文件检测和文件处理之间存在延迟。我在构建器模式中有这个:

/**
* The build function that will create a CompositeFileListFilter with the given filters
*
* @return {@link CompositeFileListFilter} that contains all the filters added
*/
public CompositeFileListFilter<File> build() {
CompositeFileListFilter<File> compositeFileListFilter = new CompositeFileListFilter<>();
boolean existsFilters = false;
// Add the prevent duplicates filter
if (this.preventDuplicates) {
compositeFileListFilter.addFilter(new AcceptOnceFileListFilter<File>());
existsFilters = true;
} else {
compositeFileListFilter.addFilter(new AcceptAllFileListFilter<File>());
existsFilters = true;
}
// Add the ignore hidden filter
if (this.ignoreHidden) {
compositeFileListFilter.addFilter(new IgnoreHiddenFileListFilter());
existsFilters = true;
} // Add the pattern file name filter
if (this.patternFilter != null) {
compositeFileListFilter.addFilter(new SimplePatternFileListFilter(patternFilter));
existsFilters = true;
}
// Add the process file after a period of time filter
if (this.lastModifiedFileListFilterAge > 0) {
LastModifiedFileListFilter filter = new LastModifiedFileListFilter();
filter.setAge(lastModifiedFileListFilterAge);
compositeFileListFilter.addFilter(filter);
existsFilters = true;
}

// Check if compositeFileListFilter contains any filter
if (!existsFilters) {
throw new IllegalStateException("At least one filter should be provided!");
}
return compositeFileListFilter;
}

我正在创建这样的过滤器

CompositeFileListFilter<File> filters = new IntegrationFlowFileFilterBuilder()
.ignoreHidden(true)
.preventDuplicates(false)
.patternFilter(returnInformationInputFolderSetup.getPatternFolder())
.lastModifiedFileListFilterAge(120)
.build();

问题是所有其他过滤器都在工作,只有 LastModifiedFileListFilter 不工作。我正在读取一个文件,并且在不到一秒的时间内处理完毕。
有谁知道为什么这个过滤器不起作用?

最佳答案

我刚刚测试了您的用例:

@Test
public void testLastModifiedInComposite() throws IOException {
CompositeFileListFilter<File> compositeFileListFilter = new CompositeFileListFilter<>();
compositeFileListFilter.addFilter(new AcceptAllFileListFilter<>());
compositeFileListFilter.addFilter(new IgnoreHiddenFileListFilter());
compositeFileListFilter.addFilter(new SimplePatternFileListFilter("*.foo"));
compositeFileListFilter.addFilter(new LastModifiedFileListFilter(120));

given(this.fileMock.getName())
.willReturn("test.foo");

given(this.fileMock.lastModified())
.willReturn(System.currentTimeMillis());

List<File> filteredFiles = compositeFileListFilter.filterFiles(new File[] { this.fileMock });

assertTrue(filteredFiles.isEmpty());

compositeFileListFilter.close();
}

请注意,我为 lastmodified 指定了当前时间,而该文件确实没有路径 LastModifiedFileListFilter。因此我得到一个空结果。只是因为我的文件太新而无法被 LastModifiedFileListFilter 接受。

我建议您调试 CompositeFileListFilter.filterFiles() 方法以确定到底发生了什么。

另请注意,有一个 ChainFileListFilter 对于过滤功能有一些不同的观点: https://docs.spring.io/spring-integration/docs/4.3.12.RELEASE/reference/html/files.html#file-reading

关于java - Spring 集成 LastModifiedFileListFilter 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47157351/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com