INT-1520: add AntPatternFileListFilter
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package org.springframework.integration.file.filters;
|
||||
|
||||
import org.springframework.integration.file.entries.AbstractEntryListFilter;
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author Iwein Fuld
|
||||
*/
|
||||
public class AntPatternFileListFilter extends AbstractEntryListFilter<File> {
|
||||
|
||||
private final AntPathMatcher matcher = new AntPathMatcher();
|
||||
private final String path;
|
||||
|
||||
public AntPatternFileListFilter(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(File file) {
|
||||
return matcher.match( path, file.getPath());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package org.springframework.integration.file.filters;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Iwein Fuld
|
||||
*
|
||||
* Minimal test set to ensure AntPathMatcher is used correctly.
|
||||
*/
|
||||
public class AntPatternFileListFilterTest {
|
||||
|
||||
@Test
|
||||
public void shouldMatchExactly() {
|
||||
assertThat(new AntPatternFileListFilter("foo/bar").accept(new File("foo/bar")), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldMatchQuestionMark() {
|
||||
assertThat(new AntPatternFileListFilter("*/bar").accept(new File("foo/bar")), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldMatchWildcard() {
|
||||
assertThat(new AntPatternFileListFilter("foo/ba?").accept(new File("foo/bar")), is(true));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user