use of org.apache.commons.io.filefilter.IOFileFilter in project applause by applause.
the class FileUtils method listFiles.
/**
* Finds files within a given directory (and optionally its
* subdirectories). All files found are filtered by an IOFileFilter.
* <p>
* If your search should recurse into subdirectories you can pass in
* an IOFileFilter for directories. You don't need to bind a
* DirectoryFileFilter (via logical AND) to this filter. This method does
* that for you.
* <p>
* An example: If you want to search through all directories called
* "temp" you pass in <code>FileFilterUtils.NameFileFilter("temp")</code>
* <p>
* Another common usage of this method is find files in a directory
* tree but ignoring the directories generated CVS. You can simply pass
* in <code>FileFilterUtils.makeCVSAware(null)</code>.
*
* @param directory the directory to search in
* @param fileFilter filter to apply when finding files.
* @param dirFilter optional filter to apply when finding subdirectories.
* If this parameter is <code>null</code>, subdirectories will not be included in the
* search. Use TrueFileFilter.INSTANCE to match all directories.
* @return an collection of java.io.File with the matching files
* @see org.apache.commons.io.filefilter.FileFilterUtils
* @see org.apache.commons.io.filefilter.NameFileFilter
*/
public static Collection<File> listFiles(File directory, IOFileFilter fileFilter, IOFileFilter dirFilter) {
if (!directory.isDirectory()) {
throw new IllegalArgumentException("Parameter 'directory' is not a directory");
}
if (fileFilter == null) {
throw new NullPointerException("Parameter 'fileFilter' is null");
}
// Setup effective file filter
IOFileFilter effFileFilter = FileFilterUtils.and(fileFilter, FileFilterUtils.notFileFilter(DirectoryFileFilter.INSTANCE));
// Setup effective directory filter
IOFileFilter effDirFilter;
if (dirFilter == null) {
effDirFilter = FalseFileFilter.INSTANCE;
} else {
effDirFilter = FileFilterUtils.and(dirFilter, DirectoryFileFilter.INSTANCE);
}
// Find files
Collection<File> files = new java.util.LinkedList<File>();
innerListFiles(files, directory, FileFilterUtils.or(effFileFilter, effDirFilter));
return files;
}
use of org.apache.commons.io.filefilter.IOFileFilter in project canal by alibaba.
the class BinLogFileQueue method listBinlogFiles.
private List<File> listBinlogFiles() {
List<File> files = new ArrayList<>();
files.addAll(FileUtils.listFiles(directory, new IOFileFilter() {
public boolean accept(File file) {
Matcher matcher = binLogPattern.matcher(file.getName());
return matcher.find();
}
public boolean accept(File dir, String name) {
return true;
}
}, null));
// 排一下序列
files.sort(Comparator.comparing(File::getName));
return files;
}
use of org.apache.commons.io.filefilter.IOFileFilter in project symmetric-ds by JumpMind.
the class FileTrigger method createIOFileFilter.
public IOFileFilter createIOFileFilter() {
String[] includes = StringUtils.isNotBlank(includesFiles) ? includesFiles.split(",") : new String[] { "*" };
String[] excludes = StringUtils.isNotBlank(excludesFiles) ? excludesFiles.split(",") : null;
IOFileFilter filter = new WildcardFileFilter(includes);
if (excludes != null && excludes.length > 0) {
List<IOFileFilter> fileFilters = new ArrayList<IOFileFilter>();
fileFilters.add(filter);
fileFilters.add(new NotFileFilter(new WildcardFileFilter(excludes)));
filter = new AndFileFilter(fileFilters);
}
if (!recurse) {
List<IOFileFilter> fileFilters = new ArrayList<IOFileFilter>();
fileFilters.add(filter);
fileFilters.add(new NotFileFilter(FileFilterUtils.directoryFileFilter()));
filter = new AndFileFilter(fileFilters);
} else {
List<IOFileFilter> fileFilters = new ArrayList<IOFileFilter>();
fileFilters.add(filter);
fileFilters.add(FileFilterUtils.directoryFileFilter());
filter = new OrFileFilter(fileFilters);
}
return filter;
}
use of org.apache.commons.io.filefilter.IOFileFilter in project pentaho-platform by pentaho.
the class PluginResourceLoader method findResources.
public List<URL> findResources(ClassLoader classLoader, String namePattern) {
// $NON-NLS-1$ //$NON-NLS-2$
String dirPattern = "", filePattern = "*";
if (namePattern.contains("/")) {
// $NON-NLS-1$
String pattern = namePattern.substring(0, namePattern.lastIndexOf('/'));
if (pattern.length() > 0) {
dirPattern = pattern;
}
pattern = namePattern.substring(namePattern.lastIndexOf('/') + 1, namePattern.length());
if (pattern.length() > 0) {
filePattern = pattern;
}
} else {
filePattern = namePattern;
}
IOFileFilter fileFilter = new WildcardFileFilter(filePattern);
IOFileFilter dirFilter = TrueFileFilter.INSTANCE;
Collection<?> files = FileUtils.listFiles(new File(getPluginDir(classLoader), dirPattern), fileFilter, dirFilter);
Iterator<?> fileIter = files.iterator();
List<URL> urls = new ArrayList<URL>(files.size());
while (fileIter.hasNext()) {
try {
urls.add(((File) fileIter.next()).toURI().toURL());
} catch (MalformedURLException e) {
// $NON-NLS-1$
Logger.warn(this, "Could not create url", e);
}
}
return urls;
}
use of org.apache.commons.io.filefilter.IOFileFilter in project pentaho-platform by pentaho.
the class PropertiesFileConfigurationTest method testUpdate.
@Test
public void testUpdate() throws Exception {
Properties props = new Properties();
props.put("one", "1");
PropertiesFileConfiguration config = new PropertiesFileConfiguration("id", props);
final File tmpPropsFile = File.createTempFile("PropertiesFileConfiguratorTest", ".properties");
config.setPropFile(tmpPropsFile);
Properties newProps = new Properties();
props.put("two", "2");
config.update(newProps);
Collection<File> files = FileUtils.listFiles(tmpPropsFile.getParentFile(), new IOFileFilter() {
@Override
public boolean accept(File file) {
return file.getName().startsWith(tmpPropsFile.getName());
}
@Override
public boolean accept(File file, String s) {
return file.getName().startsWith(tmpPropsFile.getName());
}
}, null);
assertEquals(2, files.size());
for (File file : files) {
// clean up the files manually. the delete on exit will only get the one, not the timestamped one created
// in the update method
file.deleteOnExit();
}
}
Aggregations