Example usage for org.apache.commons.io FileUtils listFiles

List of usage examples for org.apache.commons.io FileUtils listFiles

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils listFiles.

Prototype

public static Collection listFiles(File directory, String[] extensions, boolean recursive) 

Source Link

Document

Finds files within a given directory (and optionally its subdirectories) which match an array of extensions.

Usage

From source file:com.ning.arecibo.collector.persistent.EventReplayingLoadGenerator.java

public void generateEventStream() {
    resetSecondCounter();/*from  ww w  .  j  av  a  2s . c  om*/
    replayIterationStartTime = new DateTime();
    for (int i = 0; i < REPLAY_REPEAT_COUNT; i++) {
        final Collection<File> files = FileUtils.listFiles(new File(REPLAY_FILE_DIRECTORY),
                new String[] { "bin" }, false);
        firstReplayEventTimestamp = null;
        resetSecondCounter();
        for (final File file : Replayer.FILE_ORDERING.sortedCopy(files)) {
            try {
                log.info("About to read file %s", file.getAbsolutePath());
                replayer.read(file, new Function<HostSamplesForTimestamp, Void>() {

                    @Override
                    public Void apply(HostSamplesForTimestamp hostSamples) {
                        if (shuttingDown.get()) {
                            return null;
                        }
                        processSamples(hostSamples);
                        return null;
                    }
                });

            } catch (IOException e) {
                log.warn(e, "Exception replaying file: %s", file.getAbsolutePath());
            }
            if (shuttingDown.get()) {
                log.info("Exiting generateEventStream() because shutdown is true");
            }
        }
        latestHostTimes.clear();
        replayIterationStartTime = lastEndTime.plusSeconds(30);
    }
}

From source file:com.bluexml.side.integration.standalone.ApplicationStarter.java

/**
 * application.args[0] : getHostID : return the hostID getLicense : return
 * the recorded license setLicense : record a new license (must be generated
 * using the HostID) $FilePath : launch generation process from .application
 * model (or many application files if $FilePath is a directory)
 * application.args[1] : the configuration name to use for launch generation
 * process//from   w w w . ja v  a2s  .c  o m
 */
public Object start(IApplicationContext context) throws Exception {

    arguments = (String[]) context.getArguments().get("application.args");

    System.out.println("Start !!!!!!!!!!");
    long time1 = System.currentTimeMillis();
    if (!arguments[0].toString().contains(".application")) {
        File root = new File(arguments[0]);
        String[] extensions = { "application" };
        boolean recursive = true;
        try {
            Collection files = FileUtils.listFiles(root, extensions, recursive);

            for (Iterator iterator = files.iterator(); iterator.hasNext();) {
                File file = (File) iterator.next();
                System.out.println("File = " + file.getAbsolutePath());
                File fileAP = new File(file.getAbsolutePath());
                System.out.println("file.exists(): " + fileAP.exists());

                generate(fileAP);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        // Start Generation
    } else {
        // System.out.println("file.exists(): " + file.exists());

        File file = new File(arguments[0]);
        System.out.println("File = " + arguments[0]);
        generate(file);
    }

    System.out.println("End Generation");
    long time2 = System.currentTimeMillis() - time1;
    System.out.println("Time " + Long.toString(time2 / 1000));
    // System.out.println("END !!!!!!!!!!");

    return EXIT_OK;
}

From source file:com.denimgroup.threadfix.framework.impl.dotNetWebForm.WebFormsEndpointGenerator.java

File getAspxRoot(File rootDirectory) {
    Collection aspxCsFiles = FileUtils.listFiles(rootDirectory, new FileExtensionFileFilter(".config"),
            TrueFileFilter.INSTANCE);/*from w  w w.  j a v  a 2 s.c  o  m*/

    int shortestPathLength = Integer.MAX_VALUE;
    File returnFile = rootDirectory;

    for (Object aspxCsFile : aspxCsFiles) {
        if (aspxCsFile instanceof File) {
            File file = (File) aspxCsFile;
            if (file.isFile() && (file.getName().equals("web.config") || file.getName().equals("Web.config"))) {
                if (file.getAbsolutePath().length() < shortestPathLength) {
                    shortestPathLength = file.getAbsolutePath().length();
                    returnFile = file.getParentFile();
                }
            }
        }
    }

    // reference comparison ok here because we're checking to see whether the reference has changed
    assert returnFile != rootDirectory : "web.config not found.";
    return returnFile;
}

From source file:com.servicelibre.jxsl.scenario.test.xspec.XspecTestSuiteRunner.java

/**
 * Recursively load all *.xspec files under each given directories.
 * /*from  w w  w .j av a 2  s.co  m*/
 * @param directories
 */
public void setDirectories(List<File> directories) {
    testDirectoryFiles.clear();

    for (File dir : directories) {
        testDirectoryFiles.addAll(FileUtils.listFiles(dir, fileFilter, directoryFilter));
    }
}

From source file:com.thoughtworks.go.server.initializers.PluginsInitializerTest.java

@Test
public void shouldUnzipPluginsZipToPluginsPath() throws IOException {
    pluginsInitializer.initialize();/*from w  ww  .j  a v a 2 s.com*/
    assertThat(FileUtils.listFiles(goPluginsDir, null, true).size(), is(2));
}

From source file:com.offbynull.coroutines.instrumenter.asm.FileSystemClassInformationRepository.java

private void addDirectory(File directory) throws IOException {
    Validate.notNull(directory);/*from  ww  w  . j av a 2  s.c  o m*/
    Validate.isTrue(directory.isDirectory());
    for (File file : FileUtils.listFiles(directory, new String[] { "class" }, true)) {
        if (!file.getName().endsWith(".class")) {
            continue;
        }

        try (InputStream is = new FileInputStream(file)) {
            populateSuperClassMapping(is);
        }
    }
}

From source file:ibeam.maven.plugins.Tools.java

/**
 * List recursively all the files of a given directory.
 * //from   ww w . ja v  a 2s . co  m
 * @param file
 * @return a list of the files and only files (folder are not listed) contained by the given directory
 */
public static List<File> listFiles(final File file) {

    return (List<File>) FileUtils.listFiles(file, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
}

From source file:com.thoughtworks.go.domain.JobInstanceLog.java

public File getTestIndexPage() {
    File folder = new File(getArtifactFolder(), TEST_OUTPUT_FOLDER);
    if (folder.exists()) {
        Collection collection = FileUtils.listFiles(folder, new IndexHtmlFilter(), new DirFilter());
        if (!collection.isEmpty()) {
            return (File) collection.iterator().next();
        }//from w w  w  .j a v  a  2 s .c o  m
    }
    return null;
}

From source file:com.aionemu.commons.scripting.scriptmanager.ScriptManager.java

/**
 * Convenient method that is used to load all script files and libraries from specific directory.<br>
 * Descriptor is not required.<br>
 * <br>//from  www.j  av a 2  s . c  om
 * <b>If you wish complex context hierarchy - you will have to use context descriptors</b>
 * <br>
 * <br>
 * .java files are treated as sources.<br>
 * .jar files are treated as libraries.<br>
 * Both .java and .jar files will be loaded recursively
 *
 * @see #DEFAULT_COMPILER_CLASS
 * @param directory - directory with .java and .jar files
 * @throws RuntimeException if failed to load script context
 */
public synchronized void loadDirectory(File directory) throws RuntimeException {
    Collection<File> libraries = FileUtils.listFiles(directory, new String[] { "jar" }, true);
    List<File> list = Lists.newArrayList(libraries);
    try {
        loadDirectory(directory, list, DEFAULT_COMPILER_CLASS.getName());
    } catch (Exception e) {
        throw new RuntimeException(
                "Failed to load script context from directory " + directory.getAbsolutePath(), e);
    }
}

From source file:com.btoddb.fastpersitentqueue.JournalMgr.java

private void prepareJournaling() throws IOException {
    FileUtils.forceMkdir(directory);// w w w .j  ava  2 s .  c  o  m
    Collection<File> files = FileUtils.listFiles(directory, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
    if (null == files || 0 == files.size()) {
        logger.info("no previous journal files found");
        return;
    }

    logger.info("loading journal descriptors");
    numberOfEntries.set(0);
    for (File f : files) {
        JournalFile jf = new JournalFile(f);
        jf.initForReading();
        jf.close();

        JournalDescriptor jd = new JournalDescriptor(jf);
        jd.setWritingFinished(true);
        jd.adjustEntryCount(jf.getNumberOfEntries());
        journalIdMap.put(jd.getId(), jd);
        numberOfEntries.addAndGet(jf.getNumberOfEntries());
        logger.info("loaded descriptor, {}, with {} entries", jd.getId(), jd.getNumberOfUnconsumedEntries());
        journalsLoadedAtStartup++;
    }

    logger.info("completed journal descriptor loading.  found a total of {} entries", numberOfEntries.get());
}