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:functionaltests.TestXMLTransformer.java

@org.junit.Test
public void run() throws Throwable {

    File folder = new File(jobDescriptorsFolder.toURI());
    File[] testJobDescrFiles = folder.listFiles();

    File samplesJobDescrFiles = new File(System.getProperty("pa.scheduler.home") + File.separator + "samples"
            + File.separator + "jobs_descriptors");

    System.out.println(samplesJobDescrFiles.getAbsolutePath());

    Collection<File> samples = FileUtils.listFiles(samplesJobDescrFiles, new String[] { "xml" }, true);

    samples.addAll(Arrays.asList(testJobDescrFiles));

    System.out.println("Treating " + samples.size() + " job descriptors.");

    for (File file : samples) {
        try {/*from w w  w .  jav  a 2s. co  m*/
            transformAndCompare(file);
        } catch (Exception e) {
            throw new Exception("An exception occured while treating the file " + file.getAbsolutePath(), e);
        }

    }
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.sampling.Step1DebateFilter.java

/**
 * Processes the debates and extract the required debates with arguments
 *
 * @param inputDir  all debates/* w  w w .  jav a  2  s. c o m*/
 * @param outputDir output
 * @throws IOException IO Exception
 */
public static void processData(String inputDir, File outputDir) throws IOException {
    // collect some lengths statistics
    DescriptiveStatistics filteredWordCountStatistics = new DescriptiveStatistics();

    Frequency frequency = new Frequency();

    final int lowerBoundaries = MEDIAN - ARGUMENT_LENGTH_PLUS_MINUS_RANGE;
    final int upperBoundaries = MEDIAN + ARGUMENT_LENGTH_PLUS_MINUS_RANGE;

    // read all debates and filter them
    for (File file : FileUtils.listFiles(new File(inputDir), new String[] { "xml" }, false)) {
        Debate debate = DebateSerializer.deserializeFromXML(FileUtils.readFileToString(file, "utf-8"));

        // only selected debates
        if (selectedDebates.contains(debate.getDebateMetaData().getUrl())) {

            Debate debateCopy = new Debate();
            debateCopy.setDebateMetaData(debate.getDebateMetaData());

            // for counting first level arguments (those without parents) for each of the two stances
            Map<String, Integer> argumentStancesCounts = new TreeMap<>();

            for (Argument argument : debate.getArgumentList()) {
                boolean keepArgument = false;

                // hack: clean the data -- update stance for "tv" vs. "TV"
                if ("tv".equalsIgnoreCase(argument.getStance())) {
                    argument.setStance("TV");
                }

                // we have a first-level argument
                if (argument.getParentId() == null) {
                    // now check the length
                    int wordCount = argument.getText().split("\\s+").length;

                    if (wordCount >= lowerBoundaries && wordCount <= upperBoundaries) {
                        String stance = argument.getStance();

                        // update counts
                        if (!argumentStancesCounts.containsKey(stance)) {
                            argumentStancesCounts.put(stance, 0);
                        }
                        argumentStancesCounts.put(stance, argumentStancesCounts.get(stance) + 1);

                        // keep it
                        keepArgument = true;

                        // update statistics; delete later
                        filteredWordCountStatistics.addValue(wordCount);
                        frequency.addValue((wordCount / 10) * 10);

                    }
                }

                // copy to the result
                if (keepArgument) {
                    debateCopy.getArgumentList().add(argument);
                }
            }
            // get number of first-level arguments for each side
            Iterator<Map.Entry<String, Integer>> tempIter = argumentStancesCounts.entrySet().iterator();

            if (argumentStancesCounts.size() > 2) {
                //                    System.out.println("More stances: " + argumentStancesCounts);
            }

            Integer val1 = tempIter.hasNext() ? tempIter.next().getValue() : 0;
            Integer val2 = tempIter.hasNext() ? tempIter.next().getValue() : 0;

            if ((val1 + val2) >= MINIMUM_NUMBER_OF_FIRST_LEVEL_ARGUMENTS_PER_DEBATE) {
                if (val1 >= MINIMUM_NUMBER_OF_FIRST_LEVEL_ARGUMENTS_PER_SIDE
                        && val2 >= MINIMUM_NUMBER_OF_FIRST_LEVEL_ARGUMENTS_PER_SIDE) {
                    System.out.println(debate.getDebateMetaData().getUrl() + "\t"
                            + debate.getDebateMetaData().getTitle() + "\t" + argumentStancesCounts);

                    // write the output
                    String xml = DebateSerializer.serializeToXML(debateCopy);
                    FileUtils.writeStringToFile(new File(outputDir, file.getName()), xml, "utf-8");
                }
            }
        }
    }
}

From source file:com.thoughtworks.go.server.GoServer.java

private List<File> getAddonJarFiles() {
    File addonsPath = new File(systemEnvironment.get(SystemEnvironment.ADDONS_PATH));
    if (!addonsPath.exists() || !addonsPath.canRead()) {
        return new ArrayList<>();
    }/*from  w ww  .jav  a2 s .  c  o m*/

    return new ArrayList<>(FileUtils.listFiles(addonsPath, new SuffixFileFilter("jar", IOCase.INSENSITIVE),
            FalseFileFilter.INSTANCE));
}

From source file:ch.unibas.fittingwizard.infrastructure.RealExportScript.java

private File getLPunFileForMolecule(MoleculeId moleculeId) {
    String lPunFileName = moleculeId.getName() + RealLRAScript.LPunExtension;
    Collection<File> files = FileUtils.listFiles(moleculesDir, new NameFileFilter(lPunFileName),
            TrueFileFilter.TRUE);/*from   w  ww  . j ava2 s .c om*/
    if (files.size() != 1) {
        throw new RuntimeException(String.format("No or too many %s files found in %s.", lPunFileName,
                moleculesDir.getAbsolutePath()));
    }
    File lPunFile = files.iterator().next();
    return lPunFile;
}

From source file:li.klass.fhem.testsuite.category.CategorySuite.java

private static Class<?>[] getSuiteClasses() {
    String basePath = getBasePath();
    File basePathFile = new File(basePath);

    Collection javaFiles = FileUtils.listFiles(basePathFile, new String[] { "java" }, true);

    ArrayList<Class<?>> result = new ArrayList<Class<?>>();
    for (Object fileObject : javaFiles) {
        File file = (File) fileObject;
        Class<?> cls = toClass(file, basePath);

        if (cls == null || Modifier.isAbstract(cls.getModifiers())) {
            continue;
        }//from   w w  w. j a va 2s .  co  m

        result.add(cls);
    }

    return result.toArray(new Class<?>[result.size()]);
}

From source file:musicmetadatak1009705.FolderTreeView.java

private ArrayList<File> restrictingList(File root) {
    ArrayList<File> fileArray = new ArrayList<>();
    boolean recursive = true;
    Collection files = FileUtils.listFiles(root, null, recursive);
    for (Iterator iterator = files.iterator(); iterator.hasNext();) {
        File file = (File) iterator.next();
        if (file.getName().endsWith(fileName)) {
            fileArray.add(file);/*  w ww  .  j a  v a 2s . c  om*/
        }
    }
    return fileArray;
}

From source file:com.ikanow.aleph2.data_model.utils.PropertiesUtils.java

/** Gets a merged set of configs
 * @param config_dir//from   ww w  .  jav  a  2  s.c  o  m
 * @param default_config
 * @return
 */
public static Config getMergedConfig(final Optional<File> config_dir, final File default_config) {
    final Config fallback_config = ConfigFactory.parseFile(default_config);
    final List<Config> extra_confs = config_dir.map(dir -> FileUtils
            .listFiles(dir, Arrays.asList("conf", "properties", "json").toArray(new String[0]), false).stream()
            .sorted().<Config>map(f -> ConfigFactory.parseFile(f)).collect(Collectors.toList()))
            .orElse(Collections.emptyList());

    return getMergedConfig(extra_confs, fallback_config);
}

From source file:at.gv.egiz.pdfas.lib.settings.Settings.java

private void loadSettingsRecursive(File workDirectory, File file) throws PdfAsSettingsException {

    String configDir = workDirectory.getAbsolutePath() + File.separator + CFG_DIR;

    logger.debug("Loading: " + file.getName());

    try (InputStream in = new FileInputStream(file)) {

        Properties tmpProps = new Properties();
        tmpProps.load(in);//from  ww w.j a  va2s. c o  m
        properties.putAll(tmpProps);

        Map<String, String> includes = this.getValuesPrefix(INCLUDE, tmpProps);
        File contextFolder = new File(configDir);
        if (includes != null) {
            Iterator<String> includeIterator = includes.values().iterator();
            while (includeIterator.hasNext()) {
                contextFolder = new File(configDir);
                String includeFileName = includeIterator.next();

                File includeInstruction = new File(contextFolder, includeFileName);
                contextFolder = includeInstruction.getParentFile();
                String includeName = includeInstruction.getName();

                WildcardFileFilter fileFilter = new WildcardFileFilter(includeName, IOCase.SENSITIVE);
                Collection<File> includeFiles = null;

                if (contextFolder != null && contextFolder.exists() && contextFolder.isDirectory()) {
                    includeFiles = FileUtils.listFiles(contextFolder, fileFilter, null);
                }
                if (includeFiles != null && !includeFiles.isEmpty()) {
                    logger.debug("Including '" + includeFileName + "'.");
                    for (File includeFile : includeFiles) {
                        loadSettingsRecursive(workDirectory, includeFile);
                    }
                }
            }
        }

    } catch (IOException e) {
        throw new PdfAsSettingsException("Failed to read settings!", e);
    }
}

From source file:com.thoughtworks.go.agent.bootstrapper.AgentBootstrapper.java

private void cleanupTempFiles() {
    FileUtils.deleteQuietly(new File(FileUtil.TMP_PARENT_DIR));
    FileUtils.deleteQuietly(new File("exploded_agent_launcher_dependencies")); // launchers extracted from old versions
    FileUtils.listFiles(new File("."), AGENT_LAUNCHER_TMP_FILE_FILTER, FalseFileFilter.INSTANCE)
            .forEach(FileUtils::deleteQuietly);
    FileUtils.deleteQuietly(new File(new SystemEnvironment().getConfigDir(), "trust.jks"));
}

From source file:com.kelveden.rastajax.cli.Runner.java

private static File findWar() {
    final Collection<File> wars = FileUtils.listFiles(new File(System.getProperty("user.dir")),
            new String[] { "war" }, true);

    LOGGER.info("Found the following wars: " + wars.toString());

    if (wars.size() > 0) {
        return wars.iterator().next();
    } else {//w w w.  j  a va2s  . c  o m
        return null;
    }
}