Example usage for java.io FileFilter accept

List of usage examples for java.io FileFilter accept

Introduction

In this page you can find the example usage for java.io FileFilter accept.

Prototype

boolean accept(File pathname);

Source Link

Document

Tests whether or not the specified abstract pathname should be included in a pathname list.

Usage

From source file:Main.java

static List<File> recursiveGetFile(File f, FileFilter ff) {
    List<File> lf = new ArrayList<File>();
    if (f.isFile()) {
        if (ff.accept(f)) {
            lf.add(f);//from  w  w w  .  j  av  a2 s  .  c  o m
        }
    } else {
        File[] fs = f.listFiles();
        for (File tempF : fs) {
            lf.addAll(recursiveGetFile(tempF, ff));
        }
    }
    return lf;
}

From source file:org.apache.ode.utils.fs.FileUtils.java

private static void directoryEntriesInPath(List<File> collectedFiles, File parentDir, FileFilter filter) {
    if ((filter == null) || ((filter != null) && (filter.accept(parentDir)))) {
        collectedFiles.add(parentDir);//from   w w w.  jav  a2s  .  c  om
    }

    File[] allFiles = parentDir.listFiles();
    if (allFiles != null) {
        TreeSet<File> dirs = new TreeSet<File>();
        TreeSet<File> acceptedFiles = new TreeSet<File>();
        for (File f : allFiles) {
            if (f.isDirectory()) {
                dirs.add(f);
            } else {
                if ((filter == null) || ((filter != null) && (filter.accept(f)))) {
                    acceptedFiles.add(f);
                }
            }
        }
        collectedFiles.addAll(acceptedFiles);
        for (File currentFile : dirs) {
            FileUtils.directoryEntriesInPath(collectedFiles, currentFile, filter);
        }
    }
}

From source file:Main.java

/**
 * Returns count of files contained recursively in the specified directory.
 * If the dir does not exist then it returns 0.
 *///  w  ww.  ja  v  a  2 s  . c o m
public static int count(File dir, FileFilter fileFilter, boolean includeFolders) {
    int result = 0;
    if (!dir.exists()) {
        return 0;
    }
    for (final File file : dir.listFiles()) {
        if (file.isFile() && !fileFilter.accept(file)) {
            continue;
        }
        if (file.isDirectory()) {
            if (includeFolders) {
                result++;
            }
            result = result + count(file, fileFilter, includeFolders);
        } else {
            result++;
        }
    }
    return result;
}

From source file:org.neo4j.ha.upgrade.Utils.java

private static void gatherFiles(List<File> jarFiles, File directory, FileFilter filter) {
    for (File file : directory.listFiles()) {
        if (file.isDirectory())
            gatherFiles(jarFiles, file, filter);
        else if (filter.accept(file))
            jarFiles.add(file);/*from  ww w .j a  v a2 s .  c o m*/
    }
}

From source file:com.smallnn.input.FileUtil.java

public static List<File> find(File file, FileFilter filter) {
    List<File> result = new ArrayList<File>();
    LinkedList<File> stack = new LinkedList<File>();
    stack.push(file);/*  w w w  .j a v  a2  s .c  o  m*/
    while (!stack.isEmpty()) {
        File f = stack.pop();
        if (filter == null || filter.accept(f)) {
            result.add(f);
        }

        if (f.isDirectory() && f.exists()) {
            stack.addAll(Arrays.asList(f.listFiles()));
        }
    }
    return result;
}

From source file:Main.java

/**
 * @see #getAllFiles(File)//from  w  ww. j  a  v a 2s.  c  o  m
 */
public static List<File> getAllFiles(File directory, FileFilter filter) {
    final List<File> fileList = getAllFiles(directory);
    if (filter == null)
        return fileList;

    final Iterator<File> fileIterator = fileList.iterator();
    while (fileIterator.hasNext()) {
        final File file = fileIterator.next();
        if (!filter.accept(file))
            fileList.remove(file);
    }
    return fileList;
}

From source file:com.ms.commons.test.common.FileUtil.java

public static List<File> listFiles(List<File> list, File file, FileFilter filter) {
    if (file.exists()) {
        if (file.isFile()) {
            if (filter.accept(file)) {
                if (list != null) {
                    list.add(file);/*from  www  .ja  v a  2s .c  o  m*/
                }
            }
        } else if (file.isDirectory()) {
            File[] files = file.listFiles(filter);
            if (files != null) {
                for (File f : files) {
                    if (filter.accept(f)) {
                        if (f.isDirectory()) {
                            listFiles(list, f, filter);
                        } else if (f.isFile()) {
                            if (list != null) {
                                list.add(f);
                            }
                        } else {
                            throw new RuntimeException("Error file type:" + file);
                        }
                    }
                }
            }
        } else {
            throw new RuntimeException("Error file type:" + file);
        }
    }

    return list;
}

From source file:org.dashbuilder.test.MavenProjectHelper.java

public static List<File> getFolders(File root, FileFilter filter) {
    List<File> result = new ArrayList<File>();
    if (root == null || !root.isDirectory())
        return result;

    File[] files = root.listFiles();
    for (File file : files) {
        if (file.isDirectory()) {
            if (filter == null || filter.accept(file))
                result.add(file);/* w  w w  .  j  av a 2s.  c om*/
            result.addAll(getFolders(file, filter));
        }
    }
    return result;
}

From source file:de.shadowhunt.maven.plugins.packageinfo.PackageInfoPlugin.java

static boolean containsFiles(final File[] files, final FileFilter filter) {
    if (isEmpty(files)) {
        return false;
    }/*from   w ww.  ja v a2  s.co m*/

    for (final File file : files) {
        if (filter.accept(file)) {
            return true;
        }
    }
    return false;
}

From source file:com.softenido.cafedark.io.virtual.VirtualFile.java

public static VirtualFileFilter buildFilter(final FileFilter filter) {
    if (filter != null) {
        return new VirtualFileFilter() {
            public boolean accept(VirtualFile pathname) {
                return filter.accept(new File(pathname.getLastPath()));
            }/*from www  .jav a 2  s . c  om*/
        };
    }
    return null;
}