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 the list of xml files in the bookmark export folder.
 * @return The list of xml files in the bookmark export folder.
 *///from ww  w  .ja v a2  s  . c  o  m
public static List<String> getExportedBookmarksFileList() {
    List<String> result = new ArrayList<String>();

    File folder = getBookmarksExportFolder();

    if (folder != null) {

        FileFilter filter = new FileFilter() {

            @Override
            public boolean accept(File pathname) {
                if ((pathname.isFile()) && (pathname.getPath().endsWith(".xml"))) {
                    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;
}

From source file:com.fizzed.stork.assembly.AssemblyUtils.java

static public void copyStandardProjectResources(File projectDir, File outputDir) throws IOException {
    FileUtils.copyDirectory(projectDir, outputDir, new FileFilter() {
        @Override/*from   ww  w  .  ja va  2  s  .  co  m*/
        public boolean accept(File pathname) {
            String name = pathname.getName().toLowerCase();
            if (name.startsWith("readme") || name.startsWith("changelog") || name.startsWith("release")
                    || name.startsWith("license")) {
                return true;
            } else {
                return false;
            }
        }
    });
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.sequence.evaluation.EvalHelper.java

public static File[] listSubFolders(File folder) {
    File[] subFolders = folder.listFiles(new FileFilter() {
        @Override//from   w w  w .  ja  v a 2s.c o  m
        public boolean accept(File pathname) {
            return pathname.isDirectory();
        }
    });

    if (subFolders.length == 0) {
        throw new IllegalStateException("No sub-folders found in " + folder.getAbsolutePath());
    }

    return subFolders;
}

From source file:org.apache.falcon.util.FSUtils.java

public static void copyOozieShareLibsToHDFS(String shareLibLocalPath, String shareLibHdfsPath)
        throws IOException {
    File shareLibDir = new File(shareLibLocalPath);
    if (!shareLibDir.exists()) {
        throw new IllegalArgumentException("Sharelibs dir must exist for tests to run.");
    }//from  w w w . j  a  v  a 2s  . c  o  m

    File[] jarFiles = shareLibDir.listFiles(new FileFilter() {
        @Override
        public boolean accept(File file) {
            return file.isFile() && file.getName().endsWith(".jar");
        }
    });

    for (File jarFile : jarFiles) {
        copyFileToHDFS(jarFile, shareLibHdfsPath);
    }
}

From source file:Main.java

public static void addFilesRecursive(List<String> files, File location, FilenameFilter filter) {
    if (!location.exists()) {
        return;//from   w  ww  . ja va  2 s. co  m
    }

    if (!location.isDirectory()) {
        if (filter.accept(location.getParentFile(), location.getName())) {
            files.add(location.getAbsolutePath());
        }
    }

    // we are in a directory => add all files matching filter and then
    // recursively add all files in subdirectories
    File[] tmp = location.listFiles(filter);
    if (tmp != null) {
        for (File file : tmp) {
            files.add(file.getAbsolutePath());
        }
    }

    File[] dirs = location.listFiles(new FileFilter() {

        @Override
        public boolean accept(File pathname) {
            return pathname.isDirectory();
        }
    });

    if (dirs == null) {
        return;
    }
    for (File dir : dirs) {
        addFilesRecursive(files, dir, filter);
    }
}

From source file:com.taobao.datax.engine.schedule.JarLoader.java

private static URL[] getUrl(String path) {
    /* check path exist */
    if (null == path || StringUtils.isBlank(path)) {
        throw new IllegalArgumentException("Path cannot be empty .");
    }/*from w w  w  .  j  a  v  a  2  s  . co m*/

    File jarPath = new File(path);
    if (!jarPath.exists() || !jarPath.isDirectory()) {
        throw new IllegalArgumentException("Path must be directory .");
    }

    /* set filter */
    FileFilter jarFilter = new FileFilter() {
        @Override
        public boolean accept(File pathname) {
            return pathname.getName().endsWith(".jar");
        }
    };

    /* iterate all jar */
    File[] allJars = new File(path).listFiles(jarFilter);
    URL[] jarUrls = new URL[allJars.length];

    for (int i = 0; i < allJars.length; i++) {
        try {
            jarUrls[i] = allJars[i].toURI().toURL();
        } catch (MalformedURLException e) {
            logger.error(ExceptionTracker.trace(e));
            throw new DataExchangeException(e.getCause());
        }
        logger.debug(jarUrls[i]);
    }

    return jarUrls;
}

From source file:Main.java

public static FileFilter infoFileFilter() {
    return new FileFilter() {

        @Override//from   w  ww . j  av  a  2s. c o  m
        public boolean accept(File pathname) {
            if (pathname.getPath().endsWith(".info"))
                return true;
            return false;
        }
    };
}

From source file:com.sap.prd.mobile.ios.mios.XCodeTest.java

private static void getPomFiles(File root, final Set<File> pomFiles) {
    if (root.isFile())
        return;//  w ww. ja  va 2 s  .  c o m

    pomFiles.addAll(Arrays.asList(root.listFiles(new FileFilter() {

        @Override
        public boolean accept(File f) {
            // here we have the implicit assumtion that a pom file is named "pom.xml".
            // In case we introduce any test with a diffent name for a pom file we have
            // to revisit that.
            return f.isFile() && f.getName().equals("pom.xml");
        }

    })));

    for (File f : Arrays.asList(root.listFiles(new FileFilter() {

        @Override
        public boolean accept(File f) {
            return f.isDirectory();
        }
    })))
        getPomFiles(f, pomFiles);
}

From source file:hudson.init.InitScriptsExecutor.java

@Initializer(after = JOB_LOADED)
public static void init(Hudson hudson) throws IOException {
    URL bundledInitScript = hudson.servletContext.getResource("/WEB-INF/init.groovy");
    if (bundledInitScript != null) {
        logger.info("Executing bundled init script: " + bundledInitScript);
        InputStream in = bundledInitScript.openStream();
        try {/*from  w  ww.jav  a2  s .co  m*/
            String script = IOUtils.toString(in);
            logger.info(new Script(script).execute());
        } finally {
            IOUtils.closeQuietly(in);
        }
    }

    File initScript = new File(hudson.getRootDir(), "init.groovy");
    if (initScript.exists()) {
        execute(initScript);
    }

    File initScriptD = new File(hudson.getRootDir(), "init.groovy.d");
    if (initScriptD.isDirectory()) {
        File[] scripts = initScriptD.listFiles(new FileFilter() {
            @Override
            public boolean accept(File f) {
                return f.getName().endsWith(".groovy");
            }
        });
        if (scripts != null) {
            // sort to run them in a deterministic order
            Arrays.sort(scripts);
            for (File f : scripts) {
                execute(f);
            }
        }
    }
}

From source file:Main.java

DefaultMutableTreeNode addNodes(DefaultMutableTreeNode curTop, File dir) {
    String curPath = dir.getPath();
    DefaultMutableTreeNode curDir = new DefaultMutableTreeNode(curPath);
    if (curTop != null) {
        curTop.add(curDir);//from w  ww.j ava2s. c  om
    }

    List<File> files = new ArrayList<File>(Arrays.asList(dir.listFiles(new FileFilter() {
        @Override
        public boolean accept(File pathname) {
            String name = pathname.getName().toLowerCase();
            return name.endsWith(".h")
                    || (pathname.isDirectory() && !("System Volume Information".equalsIgnoreCase(name)));
        }
    })));

    Collections.sort(files);

    for (File file : files) {
        if (file.isDirectory()) {
            addNodes(curDir, file);
        }
    }
    for (File file : files) {
        if (file.isFile()) {
            curDir.add(new DefaultMutableTreeNode(file));
        }
    }
    return curDir;
}