Java Code Examples for org.apache.commons.io.filefilter.AndFileFilter

The following examples show how to use org.apache.commons.io.filefilter.AndFileFilter. These examples are extracted from open source projects. 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
/**
 * 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 SuffixFileFilter(CamsConstants.BarCodeInventory.DATA_FILE_EXTENSION);
    IOFileFilter combinedFilter = new AndFileFilter(prefixFilter, suffixFilter);

    for (File file : files) {
        if (combinedFilter.accept(file)) {
            String fileName = file.getName();
            if (fileName.endsWith(CamsConstants.BarCodeInventory.DATA_FILE_EXTENSION)) {
                extractedFileUserIdentifiers.add(StringUtils.substringBetween(fileName, prefixString, CamsConstants.BarCodeInventory.DATA_FILE_EXTENSION));
            } 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 2
public static Collection<File> getPomFiles( File repoPath )
{
    Collection<File> pomFiles = new ArrayList<File>();
    Collection<File> leafDirectories = getLeafDirectories( repoPath );
    for ( File leafDirectory : leafDirectories )
    {
        IOFileFilter fileFilter = new AndFileFilter( new WildcardFileFilter( "*.pom" ),
                                           new NotFileFilter( new SuffixFileFilter( "sha1" ) ) );
        pomFiles.addAll( FileUtils.listFiles( leafDirectory, fileFilter, null ) );
    }
    return pomFiles;
}
 
Example 3
Source Project: oxTrust   Source File: ViewLogFileAction.java    License: MIT License 5 votes vote down vote up
private Map<Integer, String> prepareLogFiles() {
	Map<Integer, String> logFiles = new HashMap<Integer, String>();

	int fileIndex = 0;
	for (SimpleCustomProperty logTemplate : this.logViewerConfiguration.getLogTemplates()) {
		String logTemplatePattern = logTemplate.getValue2();
		if (StringHelper.isEmpty(logTemplatePattern)) {
			continue;
		}

		String logTemplatePath = FilenameUtils.getFullPath(logTemplatePattern);
		String logTemplateFile = FilenameUtils.getName(logTemplatePattern);

		File logTemplateBaseDir = new File(logTemplatePath);

		FileFilter fileFilter = new AndFileFilter(FileFileFilter.FILE, new WildcardFileFilter(logTemplateFile));
		File[] files = logTemplateBaseDir.listFiles(fileFilter);
		if (files == null) {
			continue;
		}

		for (int i = 0; i < files.length; i++) {
			logFiles.put(fileIndex++, files[i].getPath());
		}
	}

	return logFiles;
}
 
Example 4
/**
 * Gets the directory walker for the default directories
 * @param customAges the custom ages, because custom age directories will not be purged
 * @return a new FilePurgeDirectoryWalker
 */
protected FilePurgeDirectoryWalker getDefaultDirectoryWalker(List<FilePurgeCustomAge> customAges) {
    IOFileFilter ageFileFilter = buildDefaultAgeFileFilter();
    if (customAges != null && customAges.size() > 0) {
        AndFileFilter andFileFilter = new AndFileFilter();
        andFileFilter.addFileFilter(ageFileFilter);
        andFileFilter.addFileFilter(buildAnyDirectoryButCustomAgeDirectoryFileFilter(customAges));
        return new FilePurgeDirectoryWalker(andFileFilter);
    } else {
        return new FilePurgeDirectoryWalker(ageFileFilter);
    }
}
 
Example 5
/**
 * @return an IOFileFilter which represents the files that should be culled by this FilePurgeCustomAge
 */
public IOFileFilter getFileFilter() {
    AndFileFilter andFileFilter = new AndFileFilter();
    MaxAgePurgeFileFilter maxAgeFilter = new MaxAgePurgeFileFilter(this);
    DirectoryNameFileFilter directoryNameFilter = new DirectoryNameFileFilter(this);
    andFileFilter.addFileFilter(maxAgeFilter);
    andFileFilter.addFileFilter(directoryNameFilter);
    return andFileFilter;
}
 
Example 6
/**
 * 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 7
Source Project: tutorials   Source File: CommonsIOUnitTest.java    License: MIT License 5 votes vote down vote up
@Test
public void whenGetFilewith_ANDFileFilter_thenFindsampletxt() throws IOException {

    String path = getClass().getClassLoader().getResource("fileTest.txt").getPath();
    File dir = FileUtils.getFile(FilenameUtils.getFullPath(path));

    Assert.assertEquals("sample.txt", dir.list(new AndFileFilter(new WildcardFileFilter("*ple*", IOCase.INSENSITIVE), new SuffixFileFilter("txt")))[0]);
}