Example usage for java.io FilenameFilter FilenameFilter

List of usage examples for java.io FilenameFilter FilenameFilter

Introduction

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

Prototype

FilenameFilter

Source Link

Usage

From source file:com.consol.citrus.admin.service.FileBrowserService.java

/**
 * Gets all sub-folder names in give directory.
 * @param directory/*from   w  w w  . j  a  v a  2s .  co m*/
 * @return
 */
public String[] getFolders(File directory) {
    if (directory.exists()) {
        String[] files = directory.list(new FilenameFilter() {
            public boolean accept(File dir, String name) {
                return name.charAt(0) != '.' && new File(dir, name).isDirectory();
            }
        });

        if (files != null) {
            Arrays.sort(files, String.CASE_INSENSITIVE_ORDER);
            return files;
        } else {
            return new String[] {};
        }
    } else {
        throw new ApplicationRuntimeException(
                "Could not open directory because it does not exist: " + directory);
    }
}

From source file:com.snaker.EngineManager.java

public void load() {
    File f = new File(ENGINE_FOLDER);
    File[] files = f.listFiles(new FilenameFilter() {

        @Override/*w w w.ja  v  a 2  s .  com*/
        public boolean accept(File dir, String name) {
            if (name.endsWith(".js"))
                return true;
            else
                return false;
        }

    });
    if (files != null && files.length > 0) {
        for (File ff : files) {
            Engine def = reloadEngine(ff);
            if (def != null) {
                engines.add(def);
            } else {
                logger.error("uncognized engine file:" + ff.getName());
            }
        }
    }
}

From source file:com.wordnik.swagger.codegen.util.FileUtil.java

public static void clearFolder(String strFolder, final String strExt) {
    File fLogDir = new File(strFolder);
    File[] fLogs = fLogDir.listFiles(new FilenameFilter() {
        public boolean accept(File fDir, String strName) {
            return (strName.endsWith(strExt));
        }/*  w  w  w.  j  av  a  2  s  .c  om*/
    });
    if (fLogs != null) {
        for (int i = 0; i < fLogs.length; i++) {
            deleteFile(fLogs[i].getAbsolutePath());
        }
    }
}

From source file:com.vilt.minium.app.controller.FileController.java

public FileController() throws IOException {
    fileDialog = new FileDialog((Frame) null, "");
    fileDialog.toFront();/*from  w  w w  .  ja v  a  2s  .c  o m*/
    fileDialog.setAlwaysOnTop(true);
    fileDialog.setFilenameFilter(new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(".js");
        }
    });
}

From source file:edu.uci.ics.asterix.installer.test.AsterixClusterLifeCycleIT.java

@BeforeClass
public static void setUp() throws Exception {
    //testcase setup
    TestCaseContext.Builder b = new TestCaseContext.Builder();
    testCaseCollection = b.build(new File(PATH_BASE));
    File outdir = new File(PATH_ACTUAL);
    outdir.mkdirs();//  w  w w.j  a va2s .  c  o  m

    //vagrant setup
    File installerTargetDir = new File(asterixProjectDir, "target");
    System.out.println(managixFolderName);
    managixFolderName = installerTargetDir.list(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return new File(dir, name).isDirectory() && name.startsWith("asterix-installer")
                    && name.endsWith("binary-assembly");
        }

    })[0];
    invoke("cp", "-r", installerTargetDir.toString() + "/" + managixFolderName,
            asterixProjectDir + "/" + CLUSTER_BASE);

    logOutput(remoteInvoke("cp -r /vagrant/" + managixFolderName + " /tmp/asterix").getInputStream());

    logOutput(managixInvoke("configure").getInputStream());
    logOutput(managixInvoke("validate").getInputStream());

    Process p = managixInvoke("create -n vagrant-ssh -c /vagrant/cluster.xml");
    String pout = processOut(p);
    LOGGER.info(pout);
    Assert.assertTrue(checkOutput(pout, "ACTIVE"));
    //TODO: I should check for 'WARNING' here, but issue 764 stops this from being reliable 
    LOGGER.info("Test start active cluster instance PASSED");

    Process stop = managixInvoke("stop -n vagrant-ssh");
    Assert.assertTrue(checkOutput(stop.getInputStream(), "Stopped Asterix instance"));
    LOGGER.info("Test stop active cluster instance PASSED");
}

From source file:com.predic8.membrane.examples.DistributionExtractingTestcase.java

@Before
public void init() throws IOException, InterruptedException {
    targetDir = new File("target").getCanonicalFile();
    if (!targetDir.exists())
        throw new RuntimeException("membraneHome " + targetDir.getName() + " does not exist.");

    File zip = null;//from  w w w  . j a v  a 2  s  .c o  m
    {
        File[] files = targetDir.listFiles(new FilenameFilter() {
            @Override
            public boolean accept(File dir, String name) {
                return name.startsWith("membrane-service-proxy") && name.endsWith(".zip");
            }
        });
        if (files.length > 1)
            throw new RuntimeException("found more than one service-proxy*.zip");
        if (files.length == 1)
            zip = files[0];
    }

    if (zip == null)
        throw new RuntimeException("TODO: calling 'ant dist-router' automatically is not implemented.");

    unzipDir = new File(targetDir, "examples-automatic");
    if (unzipDir.exists()) {
        recursiveDelete(unzipDir);
        Thread.sleep(1000);
    }
    if (!unzipDir.mkdir())
        throw new RuntimeException("Could not mkdir " + unzipDir.getAbsolutePath());

    System.out.println("unzipping router distribution [" + getClass().getSimpleName() + "]...");
    unzip(zip, unzipDir);

    membraneHome = unzipDir.listFiles(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.startsWith("membrane-service-proxy");
        }
    })[0];

    replaceLog4JConfig();

    System.out.println("running test...");
}

From source file:com.morty.podcast.writer.validation.StandardFileValidator.java

@Override
public void process() throws Exception {

    List problems = new ArrayList();
    try {//from  w  w  w  .j  ava 2  s  .  c o m
        /*
         * 1) Are there modules?
         * 2) Is there a specific info.txt file for the podcast itself
         * 3) The modules - do they have a info.txt file?
         * 4) Do any of the filenames have spaces?
         */

        if (!m_folderToProcess.exists())
            problems.add("Podcast Directory does not exist");

        //Are there folders?
        if (m_folderToProcess.listFiles().length == 0)
            problems.add("No folders in the podcast directory");

        //Are there valid folders?
        File[] modules = m_folderToProcess.listFiles(new FilenameFilter() {

            public boolean accept(File file, String fileToCheck) {
                m_logger.debug("Checking module [" + fileToCheck + "]");

                File dirCheck = new File(file + File.separator + fileToCheck);
                if (fileToCheck.toLowerCase().equals("info.txt"))
                    return false;
                if (!dirCheck.isDirectory())
                    return false;

                //if not in list, then accept. If in list, then reject the folder
                if (m_excludedFolders == null || m_excludedFolders.isEmpty())
                    return true;
                else if (m_excludedFolders.contains(fileToCheck)) {
                    m_logger.debug("Skipping excluded folder [" + fileToCheck + "]");
                    return false;
                } else
                    return true;
            }
        });

        if (modules.length == 0)
            problems.add("No valid folders in the podcast directory");

        //Is there an info.txt?
        File podcastInfo = new File(m_folderToProcess + File.separator + "info.txt");
        if (!podcastInfo.exists())
            problems.add("No podcast info.txt file.");

        //Does each module have an info.txt?
        for (int i = 0; i < modules.length; i++) {
            File moduleInfo = new File(modules[i].getAbsolutePath() + File.separator + "info.txt");
            if (!moduleInfo.exists())
                problems.add("No info file for module [" + modules[i] + "]");

        }

        //Filename resolver.
        PodCastFileNameResolver fnf = new PodCastFileNameResolver();

        //Check each filename - are there spaces?
        for (int i = 0; i < modules.length; i++) {
            File moduleDir = new File(modules[i].getAbsolutePath());
            File[] files = moduleDir.listFiles();

            //Go through each file...
            for (int j = 0; j < files.length; j++) {
                //Get the file
                File testFile = files[j];
                if (testFile.getName().toLowerCase().equals("info.txt"))
                    m_logger.info("Ignoring text file in validation");
                else if (!fnf.fileIsResolvable(testFile.getName()))
                    problems.add("Unable to resolve file [" + testFile.getName() + "] in directory ["
                            + moduleDir.getAbsolutePath() + "]");

            }

        }

        if (problems.isEmpty())
            m_logger.info("Podcast Directory seems to be valid");
        else {
            m_logger.error("\n\n");
            m_logger.error("==================================================================");
            m_logger.error("Podcast Directory is invalid for the following reasons");
            Iterator it = problems.iterator();
            while (it.hasNext()) {
                String problem = (String) it.next();
                m_logger.error(problem);

            }
            m_logger.error("==================================================================");
            m_logger.error("\n\n");

            if (m_failOnError)
                throw new Exception("Podcast Directory Invalid");
        }

    } catch (Exception e) {
        if (m_logger.isDebugEnabled())
            m_logger.debug("Unable to validate [" + e.getMessage() + "]", e);
        throw e;
    }

}

From source file:edu.rice.cs.bioinfo.programs.phylonet.PhyloNetAAT.java

public static TestSuite suite() throws Throwable {
    TestSuite aatSuite = new TestSuite();

    File currentDir = new File(".");

    for (final File file : currentDir.listFiles(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.endsWith(".txt");
        }/*from  w ww. j  a  v  a2s .  c  o m*/
    })) {

        new AATTestCase(file).runTest();

    }

    return aatSuite;
}

From source file:com.chiorichan.site.SiteManager.java

public static void cleanupBackups(final String siteId, final String suffix, int limit) {
    File dir = new File(AppConfig.get().getDirectory("archive", "archive"), siteId);
    if (!dir.exists())
        return;//from   www .j  ava  2 s .  com
    File[] files = dir.listFiles(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(suffix);
        }
    });

    if (files == null || files.length < 1)
        return;

    // Delete all logs, no archiving!
    if (limit < 1) {
        for (File f : files)
            f.delete();
        return;
    }

    FileFunc.SortableFile[] sfiles = new FileFunc.SortableFile[files.length];

    for (int i = 0; i < files.length; i++)
        sfiles[i] = new FileFunc.SortableFile(files[i]);

    Arrays.sort(sfiles);

    if (sfiles.length > limit)
        for (int i = 0; i < sfiles.length - limit; i++)
            sfiles[i].f.delete();
}

From source file:com.github.hexocraft.worldrestorer.WorldRestorerApi.java

public static ArrayList<String> listWorlds(JavaPlugin plugin) {
    File worldSavesFolder = new File(plugin.getDataFolder() + "/" + worldSaves + "/");
    String[] directories = worldSavesFolder.list(new FilenameFilter() {
        @Override/*w  ww.  j av a 2 s  .  com*/
        public boolean accept(File file, String name) {
            if (file.isDirectory()) {
                String[] settings = file.list(new FilenameFilter() {
                    @Override
                    public boolean accept(File file, String name) {
                        return name.equals(worldSettings);
                    }
                });
                if (settings != null)
                    return true;
                return false;
            } else
                return false;
        }
    });

    if (directories == null)
        return Lists.newArrayList();
    else
        return Lists.newArrayList(directories);
}