org.apache.commons.io.filefilter.OrFileFilter Java Examples

The following examples show how to use org.apache.commons.io.filefilter.OrFileFilter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IOUtil.java    From celerio with Apache License 2.0 6 votes vote down vote up
/**
 * Recurse in the folder to get the list all files and folders
 * <ul>
 * <li>do not recurse in svn folder</li>
 * <li>do not recurse in cvs folder</li>
 * <li>do not match .bak files</li>
 * <li>do not match .old files</li>
 * </ul>
 *
 * @param folder       the folder to parse
 * @param ioFileFilter additionnal IOFilter
 */
@SuppressWarnings("unchecked")
public Collection<String> listFiles(File folder, IOFileFilter ioFileFilter) {
    if (ioFileFilter == null) {
        ioFileFilter = FileFilterUtils.fileFileFilter();
    }
    OrFileFilter oldFilesFilter = new OrFileFilter();
    for (String exclude : DEFAULT_EXCLUDES_SUFFIXES) {
        oldFilesFilter.addFileFilter(FileFilterUtils.suffixFileFilter(exclude));
    }
    IOFileFilter notOldFilesFilter = FileFilterUtils.notFileFilter(oldFilesFilter);

    Collection<File> files = FileUtils.listFiles(folder, FileFilterUtils.andFileFilter(ioFileFilter, notOldFilesFilter),
            FileFilterUtils.makeSVNAware(FileFilterUtils.makeCVSAware(null)));
    Collection<String> ret = newArrayList();
    for (File file : files) {
        ret.add(file.getAbsolutePath());
    }
    return ret;
}
 
Example #2
Source File: PackagingHandler.java    From deadcode4j with Apache License 2.0 6 votes vote down vote up
/**
 * Returns each compile source root of a given <code>MavenProject</code> as a <code>Repository</code> instance
 * providing access to the Java files it contains.
 * Silently ignores compile source roots that do not exist in the file system.
 *
 * @since 2.0.0
 */
@Nonnull
protected Collection<Repository> getJavaFilesOfCompileSourceRootsAsRepositories(@Nonnull MavenProject project) {
    Collection<Repository> codeRepositories = newArrayList();
    for (String compileSourceRoot : emptyIfNull(project.getCompileSourceRoots())) {
        File compileSourceDirectory = new File(compileSourceRoot);
        if (!compileSourceDirectory.exists()) {
            logger.debug("  Compile Source Directory [{}] does not exist?", compileSourceDirectory);
            continue;
        }
        codeRepositories.add(new Repository(compileSourceDirectory,
                new OrFileFilter(DIRECTORY, new RegexFileFilter(".*\\.java$", INSENSITIVE))));
        logger.debug("  Found source directory [{}].", compileSourceRoot);
    }
    return codeRepositories;
}
 
Example #3
Source File: FilePurgeServiceImpl.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Gets a directory walker which will 
 * @param customAges the custom ages to purge files for
 * @return a new FilePurgeDirectoryWalker which will walk directories for us
 */
protected FilePurgeDirectoryWalker getCustomAgesDirectoryWalker(List<FilePurgeCustomAge> customAges) {
    OrFileFilter fileFilter = new OrFileFilter();
    for (FilePurgeCustomAge customAge : customAges) {
        fileFilter.addFileFilter(customAge.getFileFilter());
    }
    return new FilePurgeDirectoryWalker(fileFilter);
}
 
Example #4
Source File: EnterpriseFeederFileSetType.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Return set of file user identifiers from a list of files
 * 
 * @param user user who uploaded or will upload file
 * @param files list of files objects
 * @return Set containing all user identifiers from list of files
 * @see org.kuali.kfs.sys.batch.BatchInputFileSetType#extractFileUserIdentifiers(org.kuali.rice.kim.api.identity.Person, java.util.List)
 */
public Set<String> extractFileUserIdentifiers(Person user, List<File> files) {
    Set<String> extractedFileUserIdentifiers = new TreeSet<String>();

    StringBuilder buf = new StringBuilder();
    buf.append(FILE_NAME_PREFIX).append(FILE_NAME_PART_DELIMITER).append(user.getPrincipalName()).append(FILE_NAME_PART_DELIMITER);
    String prefixString = buf.toString();
    IOFileFilter prefixFilter = new PrefixFileFilter(prefixString);

    IOFileFilter suffixFilter = new OrFileFilter(new SuffixFileFilter(EnterpriseFeederService.DATA_FILE_SUFFIX), new SuffixFileFilter(EnterpriseFeederService.RECON_FILE_SUFFIX));

    IOFileFilter combinedFilter = new AndFileFilter(prefixFilter, suffixFilter);

    for (File file : files) {
        if (combinedFilter.accept(file)) {
            String fileName = file.getName();
            if (fileName.endsWith(EnterpriseFeederService.DATA_FILE_SUFFIX)) {
                extractedFileUserIdentifiers.add(StringUtils.substringBetween(fileName, prefixString, EnterpriseFeederService.DATA_FILE_SUFFIX));
            }
            else if (fileName.endsWith(EnterpriseFeederService.RECON_FILE_SUFFIX)) {
                extractedFileUserIdentifiers.add(StringUtils.substringBetween(fileName, prefixString, EnterpriseFeederService.RECON_FILE_SUFFIX));
            }
            else {
                LOG.error("Unable to determine file user identifier for file name: " + fileName);
                throw new RuntimeException("Unable to determine file user identifier for file name: " + fileName);
            }
        }
    }

    return extractedFileUserIdentifiers;
}
 
Example #5
Source File: Files.java    From chipster with MIT License 5 votes vote down vote up
/**
 * Walks the baseDir recursively and deletes files that match filter. When traversing directories, does not follow symbolic links.
 * 
 * @param baseDir
 * @param filter
 * @throws IOException 
 */
public static void walkAndDelete(File baseDir, IOFileFilter filter) throws IOException {
	File[] files = baseDir.listFiles((FileFilter)new OrFileFilter(DirectoryFileFilter.INSTANCE, filter));
	
	if (files == null) {
		return;
	}
	
	for (File f : files) {
		
		// Just try to delete it first
		// Will work for normal files, empty dirs and links (dir or file)
		// Avoid need for dealing with links later on
		if (f.delete()) {
			continue;
		} else if (f.isDirectory()) {
			
			// check the filter for directory before walking it as walking might affect the filter
			// conditions such as directory modified time
			boolean toBeDeleted = false;
			if (filter.accept(f)) {
				toBeDeleted = true;
			}

			// walk into dir
			walkAndDelete(f, filter);
			
			// possibly delete dir 
			if (toBeDeleted) {
				f.delete();
			}
		}
	}
}
 
Example #6
Source File: HsacFitNesseRunner.java    From hsac-fitnesse-fixtures with Apache License 2.0 4 votes vote down vote up
protected FileFilter getFileSectionCopyFilter(Class<?> suiteClass) {
    List<String> excludes = getFileSectionCopyExcludes(suiteClass);
    List<IOFileFilter> excludeFilters = new ArrayList<>(excludes.size());
    excludes.forEach(x -> excludeFilters.add(new WildcardFileFilter(x)));
    return new NotFileFilter(new OrFileFilter(excludeFilters));
}