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

The following examples show how to use org.apache.commons.io.filefilter.IOFileFilter. 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: JvmMetricsReaderTest.java    From varOne with MIT License 6 votes vote down vote up
private void assertContent(IOFileFilter filter, Map<String, List<MetricTuple>> result) throws IOException{
	for(Entry<String, List<MetricTuple>> entry: result.entrySet()){
		File logFile =  new File(metricsDir+"//"+entry.getKey());
		assertTrue(filter.accept(logFile));
		int lineNum = 0;
		List<MetricTuple> tuples = entry.getValue();
		List<String> lines = FileUtils.readLines(logFile);
		lines.remove(0);
		for(MetricTuple tuple: tuples){
			String[] pair = lines.get(lineNum).split(",");
			assertEquals(pair[0], String.valueOf(tuple.getTime()));
			assertEquals(pair[1], tuple.getValue());
			lineNum++;
		}
	}
}
 
Example #2
Source File: TestUtils.java    From OpenAs2App with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Wait till a file will occur on the file system.
 *
 * @param parent     a directory where file will be.
 * @param fileFilter a filter to scan the parent dir.
 * @param timeout    an amount of time units to wait
 * @param unit       a time unit
 * @return a file
 * @throws FileNotFoundException
 */
public static File waitForFile(File parent, IOFileFilter fileFilter, int timeout, TimeUnit unit) throws FileNotFoundException {
    long finishAt = System.currentTimeMillis() + unit.toMillis(timeout);
    waitForFile(parent, timeout, unit);
    while (finishAt - System.currentTimeMillis() > 0) {
        Collection<File> files = FileUtils.listFiles(parent, fileFilter, TrueFileFilter.INSTANCE);
        if (!files.isEmpty()) {
            if (files.size() > 1) {
                throw new IllegalStateException("Result is not unique.");
            } else {
                return files.iterator().next();
            }
        }
    }
    throw new FileNotFoundException(parent.getAbsolutePath() + ": " + fileFilter.toString());
}
 
Example #3
Source File: FileUtils.java    From aion-germany with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Finds files within a given directory (and optionally its
 * subdirectories). All files found are filtered by an IOFileFilter.
 *
 * @param files the collection of files found.
 * @param directory the directory to search in.
 * @param filter the filter to apply to files and directories.
 * @param includeSubDirectories indicates if will include the subdirectories themselves
 */
private static void innerListFiles(Collection<File> files, File directory,
        IOFileFilter filter, boolean includeSubDirectories) {
    File[] found = directory.listFiles((FileFilter) filter);
    
    if (found != null) {
        for (File file : found) {
            if (file.isDirectory()) {
                if (includeSubDirectories) {
                    files.add(file);
                }
                innerListFiles(files, file, filter, includeSubDirectories);
            } else {
                files.add(file);
            }
        }
    }
}
 
Example #4
Source File: FsMetricsReaderTest.java    From varOne with MIT License 6 votes vote down vote up
private void assertContent(IOFileFilter filter, Map<String, List<MetricTuple>> result) throws IOException{
	for(Entry<String, List<MetricTuple>> entry: result.entrySet()){
		File logFile =  new File(metricsDir+"//"+entry.getKey());
		assertTrue(filter.accept(logFile));
		int lineNum = 0;
		List<MetricTuple> tuples = entry.getValue();
		List<String> lines = FileUtils.readLines(logFile);
		lines.remove(0);
		for(MetricTuple tuple: tuples){
			String[] pair = lines.get(lineNum).split(",");
			assertEquals(pair[0], String.valueOf(tuple.getTime()));
			assertEquals(pair[1], tuple.getValue());
			lineNum++;
		}
	}
}
 
Example #5
Source File: PackageImpl.java    From japi with MIT License 6 votes vote down vote up
@Override
public List<IAction> getActions() {
    final IOFileFilter dirFilter = FileFilterUtils.asFileFilter(new FileFilter() {
        @Override
        public boolean accept(File pathname) {
            return pathname.getName().endsWith(".java") && !pathname.getName().equals("package-info.java");
        }
    });
    Collection<File> actionFiles = FileUtils.listFiles(packageFold, dirFilter, null);
    List<IAction> actions = new ArrayList<>();
    for (File actionFile : actionFiles) {
        ActionImpl action = new ActionImpl();
        action.setActionFile(actionFile);
        actions.add(action);
    }
    return actions;
}
 
Example #6
Source File: LicenseHeaderUpdate.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
public static void handleXMLStyleComments( String baseDir ) throws Exception {
    IOFileFilter sourceFileFilter = FileFilterUtils.orFileFilter(
            FileFilterUtils.suffixFileFilter("xml"),
            FileFilterUtils.suffixFileFilter("jrxml") );
    sourceFileFilter = FileFilterUtils.orFileFilter(
            sourceFileFilter,
            FileFilterUtils.suffixFileFilter("html") );
    sourceFileFilter = FileFilterUtils.orFileFilter(
            sourceFileFilter,
            FileFilterUtils.suffixFileFilter("htm") );
    sourceFileFilter = FileFilterUtils.orFileFilter(
            sourceFileFilter,
            FileFilterUtils.suffixFileFilter("xsd") );
    sourceFileFilter = FileFilterUtils.orFileFilter(
            sourceFileFilter,
            FileFilterUtils.suffixFileFilter("tld") );
    sourceFileFilter = FileFilterUtils.makeSVNAware(sourceFileFilter);
    sourceFileFilter = FileFilterUtils.makeFileOnly(sourceFileFilter);

    LicensableFileDirectoryWalker dw = new LicensableFileDirectoryWalker(sourceFileFilter, "<!--", "   - ", " -->");
    Collection<String> results = dw.run( baseDir );
    System.out.println( results );
}
 
Example #7
Source File: ProjectImpl.java    From japi with MIT License 6 votes vote down vote up
@Override
public List<IPackage> getPackages() {
    String masterProjectActionPath = JapiClient.getConfig().getPrefixPath() + JapiClient.getConfig().getProjectJavaPath() + JapiClient.getConfig().getPostfixPath() + "/" + JapiClient.getConfig().getActionReletivePath();
    File actionFold = new File(masterProjectActionPath);
    if (!actionFold.exists()) {
        throw new JapiException(masterProjectActionPath + " fold not exists.");
    }
    final IOFileFilter dirFilter = FileFilterUtils.asFileFilter(new FileFilter() {
        @Override
        public boolean accept(File pathname) {
            return pathname.isDirectory();
        }
    });
    Collection<File> folds = FileUtils.listFilesAndDirs(actionFold, dirFilter, TrueFileFilter.INSTANCE);
    List<IPackage> packages = new ArrayList<>(folds.size());
    for (File fold : folds) {
        if (!fold.getAbsolutePath().equals(actionFold.getAbsolutePath())) {
            PackageImpl packageImpl = new PackageImpl();
            packageImpl.setPackageFold(fold);
            packages.add(packageImpl);
        }
    }
    return packages;
}
 
Example #8
Source File: BatchFileLookupableHelperServiceImpl.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
protected IOFileFilter getPathBasedFileFilter() {
    List<File> selectedFiles = getSelectedDirectories(getSelectedPaths());
    if (selectedFiles.isEmpty()) {
        return null;
    }
    IOFileFilter fileFilter = null;
    for (File selectedFile : selectedFiles) {
        IOFileFilter subFilter = new SubDirectoryFileFilter(selectedFile);
        if (fileFilter == null) {
            fileFilter = subFilter;
        }
        else {
            fileFilter = FileFilterUtils.orFileFilter(fileFilter, subFilter);
        }
    }
    return fileFilter;
}
 
Example #9
Source File: ThreadPoolMetricsReaderTest.java    From varOne with MIT License 6 votes vote down vote up
private void assertContent(IOFileFilter filter, Map<String, List<MetricTuple>> result) throws IOException{
	for(Entry<String, List<MetricTuple>> entry: result.entrySet()){
		File logFile =  new File(metricsDir+"//"+entry.getKey());
		assertTrue(filter.accept(logFile));
		int lineNum = 0;
		List<MetricTuple> tuples = entry.getValue();
		List<String> lines = FileUtils.readLines(logFile);
		lines.remove(0);
		for(MetricTuple tuple: tuples){
			String[] pair = lines.get(lineNum).split(",");
			assertEquals(pair[0], String.valueOf(tuple.getTime()));
			assertEquals(pair[1], tuple.getValue());
			lineNum++;
		}
	}
}
 
Example #10
Source File: LicenseHeaderUpdate.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
public static void handleJavaStyleComments( String baseDir ) throws Exception {
    IOFileFilter sourceFileFilter = FileFilterUtils.orFileFilter(
            FileFilterUtils.suffixFileFilter("java"),
            FileFilterUtils.suffixFileFilter("js") );
    sourceFileFilter = FileFilterUtils.orFileFilter(
            sourceFileFilter,
            FileFilterUtils.suffixFileFilter("css") );
    sourceFileFilter = FileFilterUtils.orFileFilter(
            sourceFileFilter,
            FileFilterUtils.suffixFileFilter("groovy") );
    sourceFileFilter = FileFilterUtils.makeSVNAware(sourceFileFilter);
    sourceFileFilter = FileFilterUtils.makeFileOnly(sourceFileFilter);

    LicensableFileDirectoryWalker dw = new LicensableFileDirectoryWalker(sourceFileFilter, "/*", " * ", " */");
    Collection<String> results = dw.run( baseDir );
    System.out.println( results );
}
 
Example #11
Source File: FilesetSplit.java    From api-mining with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @param args
 */
public static void main(final String[] args) {
	if (args.length < 7) {
		System.err
				.println("Usage fromDirectory toDirectory fileSuffix <<segmentName_i> <weight_i> ...>");
		System.exit(-1);
	}

	final File fromDirectory = new File(args[0]);
	final File toDirectory = new File(args[1]);

	final IOFileFilter fileFilter = FileFilterUtils
			.suffixFileFilter(args[2]);

	final Map<String, Double> segments = Maps.newHashMap();

	for (int i = 3; i < args.length; i += 2) {
		segments.put(args[i], Double.valueOf(args[i + 1]));
	}

	LOGGER.info("Splitting files in segments " + segments);
	splitFiles(fromDirectory, toDirectory, segments, fileFilter,
			UNIFORM_FILE_WEIGHT);
}
 
Example #12
Source File: MetaModelBuilder.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private static List<File> classpath(File o2oadir, File outputdir) {
	List<File> cp = new ArrayList<>();

	cp.add(outputdir);

	IOFileFilter filter = new WildcardFileFilter("x_base_core_project.jar");
	for (File o : FileUtils.listFiles(new File(o2oadir, "o2server/store/jars"), filter, null)) {
		cp.add(o);
	}

	ClassLoader cl = MetaModelBuilder.class.getClassLoader();

	URL[] urls = ((URLClassLoader) cl).getURLs();

	for (URL url : urls) {
		cp.add(new File(url.getFile()));
	}
	return cp;
}
 
Example #13
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 #14
Source File: JvmMetricsReaderTest.java    From varOne with MIT License 5 votes vote down vote up
/**
 * Test method for {@link com.varone.node.reader.JvmMetricsReader#read(java.lang.String, java.lang.String)}.
 * @throws IOException 
 */
public void testRead_JVM_NON_HEAP_USAGE() throws IOException {
	MetricsReader reader = new JvmMetricsReader(null, MetricsType.JVM_NON_HEAP_USAGE);
	
	String applicationId = "application_1439169262151_0237";
	
	Map<String, List<MetricTuple>> result = reader.read(applicationId, metricsDir);
	IOFileFilter filter = new RegexFileFilter(applicationId+"(.\\d+)."+MetricsType.JVM_NON_HEAP_USAGE.type()+".csv");
	
	assertEquals(result.size(), 2);  
	this.assertContent(filter, result);
}
 
Example #15
Source File: JvmMetricsReaderTest.java    From varOne with MIT License 5 votes vote down vote up
/**
 * Test method for {@link com.varone.node.reader.JvmMetricsReader#read(java.lang.String, java.lang.String)}.
 * @throws IOException 
 */
public void testRead_JVM_PS_SCAVENGE_COUNT() throws IOException {
	MetricsReader reader = new JvmMetricsReader(null, MetricsType.JVM_PS_SCAVENGE_COUNT);
	
	String applicationId = "application_1439169262151_0237";
	
	Map<String, List<MetricTuple>> result = reader.read(applicationId, metricsDir);
	IOFileFilter filter = new RegexFileFilter(applicationId+"(.\\d+)."+MetricsType.JVM_PS_SCAVENGE_COUNT.type()+".csv");
	
	assertEquals(result.size(), 2);  
	this.assertContent(filter, result);
}
 
Example #16
Source File: JvmMetricsReaderTest.java    From varOne with MIT License 5 votes vote down vote up
/**
 * Test method for {@link com.varone.node.reader.JvmMetricsReader#read(java.lang.String, java.lang.String)}.
 * @throws IOException 
 */
public void testRead_JVM_POOLS_PS_PERM_GEN_USAGE() throws IOException {
	MetricsReader reader = new JvmMetricsReader(null, MetricsType.JVM_POOLS_PS_PERM_GEN_USAGE);
	
	String applicationId = "application_1439169262151_0237";
	
	Map<String, List<MetricTuple>> result = reader.read(applicationId, metricsDir);
	IOFileFilter filter = new RegexFileFilter(applicationId+"(.\\d+)."+MetricsType.JVM_POOLS_PS_PERM_GEN_USAGE.type()+".csv");
	
	assertEquals(result.size(), 2);  
	this.assertContent(filter, result);
}
 
Example #17
Source File: JvmMetricsReaderTest.java    From varOne with MIT License 5 votes vote down vote up
/**
 * Test method for {@link com.varone.node.reader.JvmMetricsReader#read(java.lang.String, java.lang.String)}.
 * @throws IOException 
 */
public void testRead_JVM_PS_MARKSWEEP_COUNT() throws IOException {
	MetricsReader reader = new JvmMetricsReader(null, MetricsType.JVM_PS_MARKSWEEP_COUNT);
	
	String applicationId = "application_1439169262151_0237";
	
	Map<String, List<MetricTuple>> result = reader.read(applicationId, metricsDir);
	IOFileFilter filter = new RegexFileFilter(applicationId+"(.\\d+)."+MetricsType.JVM_PS_MARKSWEEP_COUNT.type()+".csv");
	
	assertEquals(result.size(), 2);  
	this.assertContent(filter, result);
}
 
Example #18
Source File: FsMetricsReaderTest.java    From varOne with MIT License 5 votes vote down vote up
/**
 * Test method for {@link com.varone.node.reader.FsMetricsReader#read(java.lang.String, java.lang.String)}.
 * @throws IOException 
 */
public void testReadWith_EXEC_FS_LOCAL_READ_OPS() throws IOException {
	MetricsReader reader = new FsMetricsReader(null, MetricsType.EXEC_FS_LOCAL_READ_OPS);
	
	String applicationId = "application_1439169262151_0237";
	
	Map<String, List<MetricTuple>> result = reader.read(applicationId, metricsDir);
	IOFileFilter filter = new RegexFileFilter(applicationId+"(.\\d+)."+MetricsType.EXEC_FS_LOCAL_READ_OPS.type()+".csv");
	
	assertEquals(result.size(), 2);  
	this.assertContent(filter, result);
}
 
Example #19
Source File: FsMetricsReaderTest.java    From varOne with MIT License 5 votes vote down vote up
/**
 * Test method for {@link com.varone.node.reader.FsMetricsReader#read(java.lang.String, java.lang.String)}.
 * @throws IOException 
 */
public void testReadWith_EXEC_FS_HDFS_WRITE_OPS() throws IOException {
	MetricsReader reader = new FsMetricsReader(null, MetricsType.EXEC_FS_HDFS_WRITE_OPS);
	
	String applicationId = "application_1439169262151_0237";
	
	Map<String, List<MetricTuple>> result = reader.read(applicationId, metricsDir);
	IOFileFilter filter = new RegexFileFilter(applicationId+"(.\\d+)."+MetricsType.EXEC_FS_HDFS_WRITE_OPS.type()+".csv");
	
	assertEquals(result.size(), 2);  
	this.assertContent(filter, result);
}
 
Example #20
Source File: ImportWorker.java    From magarena with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Copies H2 game stats database file BUT ONLY if the stats folder
 * has been not yet been created (ie. post-install, not if you re-run
 * the import process via the "Reset & restart" option).
 */
private void importGameStats() throws IOException {
    setProgressNote(MText.get(_S14));
    String directoryName = "stats";
    Path sourcePath = importDataPath.resolve(directoryName);
    Path targetPath = MagicFileSystem.getDataPath().resolve(directoryName);
    if (sourcePath.toFile().exists() && MagicFileSystem.isMissingOrEmpty(targetPath)) {
        IOFileFilter dbSuffixFilter = FileFilterUtils.suffixFileFilter(".db");
        FileUtils.copyDirectory(sourcePath.toFile(), targetPath.toFile(), dbSuffixFilter);
    }
    setProgressNote(OK_STRING);
}
 
Example #21
Source File: JvmMetricsReaderTest.java    From varOne with MIT License 5 votes vote down vote up
/**
 * Test method for {@link com.varone.node.reader.JvmMetricsReader#read(java.lang.String, java.lang.String)}.
 * @throws IOException 
 */
public void testRead_JVM() throws IOException {
	MetricsReader reader = new JvmMetricsReader(null, MetricsType.JVM);
	
	String applicationId = "application_1439169262151_0237";
	
	Map<String, List<MetricTuple>> result = reader.read(applicationId, metricsDir);
	IOFileFilter filter = new RegexFileFilter(applicationId+"(.\\d+).jvm.(?!total).*\\.csv");
	
	assertEquals(result.size(), 38);  
	this.assertContent(filter, result);
}
 
Example #22
Source File: ThreadPoolMetricsReaderTest.java    From varOne with MIT License 5 votes vote down vote up
/**
 * Test method for {@link com.varone.node.reader.ThreadPoolMetricsReader#read(java.lang.String, java.lang.String)}.
 * @throws IOException 
 */
public void testRead_EXEC_THREADPOOL_ACTIVETASK() throws IOException {
	MetricsReader reader = new ThreadPoolMetricsReader(null, MetricsType.EXEC_THREADPOOL_ACTIVETASK);
	
	String applicationId = "application_1439169262151_0237";
	String metricsDir = this.getClass().getResource("/csvsink").getPath();
	
	Map<String, List<MetricTuple>> result = reader.read(applicationId, metricsDir);
	IOFileFilter filter = new RegexFileFilter(applicationId+"(.\\d+)."+MetricsType.EXEC_THREADPOOL_ACTIVETASK.type()+".csv");
	
	assertEquals(result.size(), 2);  
	this.assertContent(filter, result);
}
 
Example #23
Source File: FilesetSplit.java    From tassal with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 
 * @param fromDirectory
 * @param toDirectory
 * @param isIncluded
 * @param segments
 *            the partition percentages to be used in the split, along with
 *            the name of the folders to be created.
 * @param weightingFunction
 *            the function that returns the weight of each file in the split
 */
public static void splitFiles(final File fromDirectory,
		final File toDirectory, final Map<String, Double> segments,
		final IOFileFilter isIncluded,
		final Function<File, Double> weightingFunction) {
	final Collection<File> fromFiles = FileUtils.listFiles(fromDirectory,
			isIncluded, DirectoryFileFilter.DIRECTORY);

	final Map<File, Double> fileWeights = Maps.newHashMap();
	for (final File f : fromFiles) {
		fileWeights.put(f, weightingFunction.apply(f));
	}

	final Multimap<String, File> fileSplit = SampleUtils.randomPartition(
			fileWeights, segments);
	// Start copying
	final String pathSeparator = System.getProperty("file.separator");
	for (final Entry<String, File> file : fileSplit.entries()) {
		final File targetFilename = new File(toDirectory.getAbsolutePath()
				+ pathSeparator + file.getKey() + pathSeparator
				+ file.getValue().getName());
		try {
			FileUtils.copyFile(file.getValue(), targetFilename);
		} catch (final IOException e) {
			LOGGER.severe("Failed to copy " + file.getValue() + " to "
					+ targetFilename);
		}
	}

}
 
Example #24
Source File: FsMetricsReaderTest.java    From varOne with MIT License 5 votes vote down vote up
/**
 * Test method for {@link com.varone.node.reader.FsMetricsReader#read(java.lang.String, java.lang.String)}.
 * @throws IOException 
 */
public void testReadWith_EXEC_FS_LOCAL_READ_BYTES() throws IOException {
	MetricsReader reader = new FsMetricsReader(null, MetricsType.EXEC_FS_LOCAL_READ_BYTES);
	
	String applicationId = "application_1439169262151_0237";
	
	Map<String, List<MetricTuple>> result = reader.read(applicationId, metricsDir);
	IOFileFilter filter = new RegexFileFilter(applicationId+"(.\\d+)."+MetricsType.EXEC_FS_LOCAL_READ_BYTES.type()+".csv");
	
	assertEquals(result.size(), 2);  
	this.assertContent(filter, result);
}
 
Example #25
Source File: FilesetSplit.java    From api-mining with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 
 * @param fromDirectory
 * @param toDirectory
 * @param isIncluded
 * @param segments
 *            the partition percentages to be used in the split, along with
 *            the name of the folders to be created.
 * @param weightingFunction
 *            the function that returns the weight of each file in the split
 */
public static void splitFiles(final File fromDirectory,
		final File toDirectory, final Map<String, Double> segments,
		final IOFileFilter isIncluded,
		final Function<File, Double> weightingFunction) {
	final Collection<File> fromFiles = FileUtils.listFiles(fromDirectory,
			isIncluded, DirectoryFileFilter.DIRECTORY);

	final Map<File, Double> fileWeights = Maps.newHashMap();
	for (final File f : fromFiles) {
		fileWeights.put(f, weightingFunction.apply(f));
	}

	final Multimap<String, File> fileSplit = SampleUtils.randomPartition(
			fileWeights, segments);
	// Start copying
	final String pathSeparator = System.getProperty("file.separator");
	for (final Entry<String, File> file : fileSplit.entries()) {
		final File targetFilename = new File(toDirectory.getAbsolutePath()
				+ pathSeparator + file.getKey() + pathSeparator
				+ file.getValue().getName());
		try {
			FileUtils.copyFile(file.getValue(), targetFilename);
		} catch (final IOException e) {
			LOGGER.severe("Failed to copy " + file.getValue() + " to "
					+ targetFilename);
		}
	}

}
 
Example #26
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 #27
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 #28
Source File: AllureFileUtils.java    From allure1 with Apache License 2.0 5 votes vote down vote up
/**
 * Returns list of files matches filters in specified directories
 *
 * @param directories which will using to find files
 * @param fileFilter  file filter
 * @param dirFilter   directory filter
 * @return list of files matches filters in specified directories
 */
public static List<File> listFiles(File[] directories, IOFileFilter fileFilter, IOFileFilter dirFilter) {
    List<File> files = new ArrayList<>();
    for (File directory : directories) {
        if (!directory.isDirectory()) {
            continue;
        }
        Collection<File> filesInDirectory = FileUtils.listFiles(directory,
                fileFilter,
                dirFilter);
        files.addAll(filesInDirectory);
    }
    return files;
}
 
Example #29
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 #30
Source File: NUZipFileGenerator.java    From neembuu-uploader with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get all accounts.
 * @return Returns all the account classes.
 */
private Collection<File> getAllAccounts(){
    return FileUtils.listFiles(new File(accountsDirectory), new IOFileFilter() {

        @Override
        public boolean accept(File file) {
            return FilenameUtils.isExtension(file.getName(), "class");
        }

        @Override
        public boolean accept(File dir, String name) {
            return dir.getName().equals("accounts");
        }
    }, null);
}