Example usage for java.io FileFilter FileFilter

List of usage examples for java.io FileFilter FileFilter

Introduction

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

Prototype

FileFilter

Source Link

Usage

From source file:Main.java

/**
 * Get all temp files.//  w  w w  .j a v a 2s . co m
 *
 * @return The list of existing temp files.
 */
public static File[] getTempCameraFiles() {
    File tempDir = getTempCameraFolder();

    File[] files = tempDir.listFiles(new FileFilter() {
        @Override
        public boolean accept(@NonNull final File file) {
            return file.isFile();
        }
    });
    if (files == null) {
        files = new File[0];
    }
    Arrays.sort(files);

    return files;
}

From source file:Main.java

/** 
 * Gets the number of cores available in this device, across all processors. 
 * Requires: Ability to peruse the filesystem at "/sys/devices/system/cpu" 
 * @return The number of cores, or 1 if failed to get result 
 *///from w ww  . j a v  a  2 s .  co m
public static int getNumCores() {
    try {
        //Get directory containing CPU info 
        File dir = new File("/sys/devices/system/cpu/");
        //Filter to only list the devices we care about 
        File[] files = dir.listFiles(new FileFilter() {

            @Override
            public boolean accept(File pathname) {
                //Check if filename is "cpu", followed by a single digit number 
                if (Pattern.matches("cpu[0-9]", pathname.getName())) {
                    return true;
                }
                return false;
            }

        });
        //Return the number of cores (virtual CPU devices) 
        return files.length;
    } catch (Exception e) {
        //Default to return 1 core 
        return 1;
    }
}

From source file:Main.java

/**
 * Look for the resource directory with raw beneath it.
 *//* w w w  .j av  a  2s.co  m*/
private static File findResRawDir(File dir) {
    for (File file : dir.listFiles()) {
        if (file.getName().equals(RESOURCE_DIR_NAME) && file.isDirectory()) {
            File[] rawFiles = file.listFiles(new FileFilter() {
                public boolean accept(File file) {
                    return file.getName().equals(RAW_DIR_NAME) && file.isDirectory();
                }
            });
            if (rawFiles.length == 1) {
                return rawFiles[0];
            }
        }
    }
    return null;
}

From source file:Main.java

public static FileFilter getFileFilter(final String reg, boolean isdir) {
    if (isdir) {// www .jav  a 2 s.c om
        return new FileFilter() {
            @Override
            public boolean accept(File pathname) {

                return pathname.getAbsolutePath().toLowerCase().matches(reg) || pathname.isDirectory();
            }
        };
    } else {
        return new FileFilter() {
            @Override
            public boolean accept(File pathname) {

                return pathname.getAbsolutePath().toLowerCase().matches(reg) && pathname.isFile();
            }
        };
    }
}

From source file:Main.java

public static File[] getAppFolders() {
    File odk = new File(getOdkFolder());

    File[] results = odk.listFiles(new FileFilter() {

        @Override//from w w  w  . j  a  va2 s .  com
        public boolean accept(File pathname) {
            if (!pathname.isDirectory())
                return false;
            return true;
        }
    });

    return results;
}

From source file:Main.java

/**
 * Gets the number of cores available in this device, across all processors.
 * Requires: Ability to peruse the filesystem at "/sys/devices/system/cpu"
 * @return The number of cores, or 1 if failed to get result
 *//*  w  ww  . j a va  2 s .  c  om*/
public static int getNumCores() {
    try {
        //Get directory containing CPU info
        File dir = new File("/sys/devices/system/cpu/");
        //Filter to only list the devices we care about
        File[] files = dir.listFiles(new FileFilter() {

            @Override
            public boolean accept(File pathname) {
                //Check if filename is "cpu", followed by a single digit number
                return Pattern.matches("cpu[0-9]", pathname.getName());
            }

        });
        //Return the number of cores (virtual CPU devices)
        return files.length;
    } catch (Exception e) {
        //Default to return 1 core
        return 1;
    }
}

From source file:Main.java

public static Collection<File> listFiles(File dir, FileFilter filter) {
    Collection<File> accumulator = new ArrayList<File>();

    if (dir.isFile()) {
        return accumulator;
    }/*from w w  w .  j  av  a 2s.  c  o  m*/

    if (filter == null) {
        // Set default filter to accept any file
        filter = new FileFilter() {
            public boolean accept(File pathname) {
                return true;
            }
        };
    }

    innerListFiles(dir, accumulator, filter);
    return accumulator;
}

From source file:Main.java

/** 
 * Gets the number of cores available in this device, across all processors. 
 * Requires: Ability to peruse the filesystem at "/sys/devices/system/cpu" 
 * @return The number of cores, or 1 if failed to get result 
 *///  w ww .  j  a  v a 2s  .c o m
public static int getNumCores() {
    try {
        //Get directory containing CPU info 
        File dir = new File("/sys/devices/system/cpu/");
        //Filter to only list the devices we care about 
        File[] files = dir.listFiles(new FileFilter() {

            @Override
            public boolean accept(File pathname) {
                //Check if filename is "cpu", followed by a single digit number 
                if (Pattern.matches("cpu[0-9]", pathname.getName())) {
                    return true;
                }
                return false;
            }

        });
        //Return the number of cores (virtual CPU devices) 
        return files.length;
    } catch (Exception e) {
        e.printStackTrace();
        return 1;
    }
}

From source file:Main.java

/**
 * Gets the number of cores available in this device, across all processors.
 * Requires: Ability to peruse the filesystem at "/sys/devices/system/cpu"
 *
 * @return The number of cores, or 1 if failed to get result
 *//*from   w  w  w .  j a v a2  s.com*/
public static int getNumCores() {
    try {
        //Get directory containing CPU info 
        File dir = new File("/sys/devices/system/cpu/");
        //Filter to only list the devices we care about 
        File[] files = dir.listFiles(new FileFilter() {

            @Override
            public boolean accept(File pathname) {
                //Check if filename is "cpu", followed by a single digit number 
                return Pattern.matches("cpu[0-9]", pathname.getName());
            }

        });
        //Return the number of cores (virtual CPU devices) 
        if (files != null)
            return files.length;
        return 1;
    } catch (Exception e) {
        e.printStackTrace();
        return 1;
    }
}

From source file:Main.java

/**
 * Get the list of xml files in the bookmark export folder.
 * @return The list of xml files in the bookmark export folder.
 *///from  ww w  .jav  a  2s. c o m
public static List<String> getExportedBookmarksFileList() {
    List<String> result = new ArrayList<String>();

    File folder = Environment.getExternalStorageDirectory();

    if (folder != null) {

        FileFilter filter = new FileFilter() {

            @Override
            public boolean accept(File pathname) {
                if ((pathname.isFile()) && (pathname.getPath().toLowerCase(Locale.US).endsWith(".xml")
                        || pathname.getPath().toLowerCase(Locale.US).endsWith(".json"))) {
                    return true;
                }
                return false;
            }
        };

        File[] files = folder.listFiles(filter);

        for (File file : files) {
            result.add(file.getName());
        }
    }

    Collections.sort(result, new Comparator<String>() {

        @Override
        public int compare(String arg0, String arg1) {
            return arg1.compareTo(arg0);
        }
    });

    return result;
}