Java Code Examples for org.apache.commons.io.filefilter.FileFilterUtils#andFileFilter()

The following examples show how to use org.apache.commons.io.filefilter.FileFilterUtils#andFileFilter() . 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: FileFilterHelper.java    From appassembler with MIT License 5 votes vote down vote up
/**
 * Make the given IOFileFilter aware of directories.
 *
 * @param filter The filter to make aware of directories.
 * @param directoryName The directory name which should be payed attention to.
 * @return The new generated filter.
 */
public static IOFileFilter makeDirectoryAware( IOFileFilter filter, String directoryName )
{

    IOFileFilter directoryAwareFilter =
        FileFilterUtils.notFileFilter( FileFilterUtils.andFileFilter( FileFilterUtils.directoryFileFilter(),
                                                                      FileFilterUtils.nameFileFilter( directoryName ) ) );

    return FileFilterUtils.andFileFilter( filter, directoryAwareFilter );
}
 
Example 2
Source File: FileFilterHelper.java    From appassembler with MIT License 5 votes vote down vote up
/**
 * Make the given IOFileFilter aware of files.
 *
 * @param filter The filter to make aware of files.
 * @param fileName The file name which should be payed attention to.
 * @return The new generated filter.
 */
public static IOFileFilter makeFileNameAware( IOFileFilter filter, String fileName )
{
    IOFileFilter directoryAwareFilter =
        FileFilterUtils.notFileFilter( FileFilterUtils.andFileFilter( FileFilterUtils.fileFileFilter(),
                                                                      FileFilterUtils.nameFileFilter( fileName ) ) );

    return FileFilterUtils.andFileFilter( filter, directoryAwareFilter );
}
 
Example 3
Source File: FileFilterHelper.java    From appassembler with MIT License 5 votes vote down vote up
/**
 * Make the given IOFileFilter aware of an suffix.
 *
 * @param filter The filter to make aware of an suffix.
 * @param suffixFileName The suffix name which should be payed attention to.
 * @return The new generated filter.
 */
public static IOFileFilter makeSuffixAware( IOFileFilter filter, String suffixFileName )
{
    IOFileFilter directoryAwareFilter =
        FileFilterUtils.notFileFilter( FileFilterUtils.andFileFilter( FileFilterUtils.fileFileFilter(),
                                                                      FileFilterUtils.suffixFileFilter( suffixFileName ) ) );

    return FileFilterUtils.andFileFilter( filter, directoryAwareFilter );
}
 
Example 4
Source File: FileFilterHelper.java    From appassembler with MIT License 5 votes vote down vote up
/**
 * Make the given IOFileFilter aware of the given pattern.
 *
 * @param filter The filter to make aware of the pattern.
 * @param pattern The pattern which should be payed attention to.
 * @return The new generated filter.
 */
public static IOFileFilter makePatternFileNameAware( IOFileFilter filter, String pattern )
{
    IOFileFilter directoryAwareFilter =
        FileFilterUtils.notFileFilter( FileFilterUtils.andFileFilter( FileFilterUtils.fileFileFilter(),
                                                                      new RegexFileFilter( pattern ) ) );

    return FileFilterUtils.andFileFilter( filter, directoryAwareFilter );
}
 
Example 5
Source File: BatchFileLookupableHelperServiceImpl.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
    List<BatchFile> results = new ArrayList<BatchFile>();

    IOFileFilter filter = FileFilterUtils.fileFileFilter();
    
    IOFileFilter pathBasedFilter = getPathBasedFileFilter();
    if (pathBasedFilter != null) {
        filter = FileFilterUtils.andFileFilter(filter, pathBasedFilter);
    }
    
    String fileNamePattern = fieldValues.get("fileName");
    IOFileFilter fileNameBasedFilter = getFileNameBasedFilter(fileNamePattern);
    if (fileNameBasedFilter != null) {
        filter = FileFilterUtils.andFileFilter(filter, fileNameBasedFilter);
    }
    
    String lastModifiedDate = fieldValues.get("lastModifiedDate");
    IOFileFilter lastModifiedDateBasedFilter = getLastModifiedDateBasedFilter(lastModifiedDate);
    if (lastModifiedDateBasedFilter != null) {
        filter = FileFilterUtils.andFileFilter(filter, lastModifiedDateBasedFilter);
    }
    
    BatchFileFinder finder = new BatchFileFinder(results, filter);
    List<File> rootDirectories = BatchFileUtils.retrieveBatchFileLookupRootDirectories();
    finder.find(rootDirectories);
    
    return results;
}
 
Example 6
Source File: ReportAggregationStep.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
protected List<File> retrieveFilesToAggregate() {
    File inputDirectory = new File(inputFilePath);
    if (!inputDirectory.exists() || !inputDirectory.isDirectory()) {
        throw new RuntimeException(inputFilePath + " does not exist or is not a directory.");
    }
    FileFilter filter = FileFilterUtils.andFileFilter(
            new PrefixFileFilter(inputFilePrefix), new SuffixFileFilter(inputFileSuffix));
    
    List<File> fileList = Arrays.asList(inputDirectory.listFiles(filter));
    
    Collections.sort(fileList);
    
    return fileList;
}
 
Example 7
Source File: CorrectionDocumentServiceImpl.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
protected List<File> getReportsToAggregateIntoReport(String documentNumber) {
    File inputDirectory = new File(temporaryReportsDirectory);
    if (!inputDirectory.exists() || !inputDirectory.isDirectory()) {
        LOG.error(temporaryReportsDirectory + " does not exist or is not a directory.");
        throw new RuntimeException("Unable to locate temporary reports directory");
    }
    String filePrefix = documentNumber + "_" + temporaryReportFilenameComponent;
    FileFilter filter = FileFilterUtils.andFileFilter(
            new PrefixFileFilter(filePrefix), new SuffixFileFilter(temporaryReportFilenameSuffix));
    
    // FSKD-244, KFSMI-5424 sort with filename, just in case 
    List<File> fileList = Arrays.asList(inputDirectory.listFiles(filter));
    
    Comparator fileNameComparator = new Comparator() {
        public int compare(Object obj1, Object obj2) {
            if (obj1 == null) {
                return -1;
            }
            if (obj2 == null) {
                return 1;
            }
            File file1 = (File) obj1;
            File file2 = (File) obj2;
            
            return ((Comparable) file1.getName()).compareTo(file2.getName());
        }
    };
    
    Collections.sort(fileList, fileNameComparator);
    return fileList ;
}