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:it.marcoberri.mbmeteo.action.Commons.java

public static void importLogPywws(Logger log) {
    try {/*from w w w.  ja v  a2  s.co  m*/

        final File importPath = new File(ConfigurationHelper.prop.getProperty("import.loggerPywws.filepath"));
        FileUtils.forceMkdir(importPath);
        final File importPathBackup = new File(
                ConfigurationHelper.prop.getProperty("import.loggerPywws.filepath") + File.separator + "old"
                        + File.separator);
        FileUtils.forceMkdir(importPathBackup);
        boolean hasHeader = Default
                .toBoolean(ConfigurationHelper.prop.getProperty("import.loggerPywws.hasHeader"), false);

        final String[] extension = { "csv", "txt" };
        Collection<File> files = FileUtils.listFiles(importPath, extension, false);

        if (files.isEmpty()) {
            log.debug("No file to inport: " + importPath);
            return;
        }

        for (File f : files) {
            log.debug("read file:" + f);

            final List<String> l = FileUtils.readLines(f, "UTF-8");
            log.debug("tot line:" + l.size());

        }

    } catch (Exception ex) {
        log.fatal(ex);

    }
}

From source file:fr.norsys.asoape.anttask.GenerateAndroidClientTask.java

@Override
public void execute() throws BuildException {
    WSDLGenerator generator = new WSDLGenerator();
    generator.setOutputDirectory(destDir);
    generator.setBeanSerializable(beanSerializable);
    for (File definitionFile : FileUtils.listFiles(wsdlDir, new String[] { "wsdl" }, true)) {
        Definition definition = readDefinitionFrom(definitionFile);
        try {/*w ww. j ava2  s  . co m*/
            generator.generateFrom(definition);
        } catch (WSDLGenerationException cause) {
            throw new BuildException("Error occurs during code generation process", cause);
        }
    }
}

From source file:com.bancvue.mongomigrate.CreateCommandTests.java

@After
public void tearDown() throws IOException {
    // Delete all js files in that the test may have created.
    File directory = new File(".");
    Collection<File> files = FileUtils.listFiles(directory, new WildcardFileFilter("*.js"), null);
    for (File file : files) {
        FileUtils.deleteQuietly(file);//from   www  . ja  va2 s  .  co  m
    }

    // Delete migrations folder
    File migrationsFolder = new File("migrations");
    FileUtils.deleteDirectory(migrationsFolder);
}

From source file:ch.ivyteam.ivy.maven.BaseEngineProjectMojoTest.java

protected final static Collection<File> findFiles(File dir, String fileExtension) {
    if (!dir.exists()) {
        return Collections.emptyList();
    }//from   w  w w .  j  a va 2 s  .co  m
    return FileUtils.listFiles(dir, new String[] { fileExtension }, true);
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.svmlib.regression.SVMLibRegressionExperimentRunner.java

@Override
public void runCrossValidation(File dataDir) throws IOException {
    Set<SinglePrediction> allPredictions = new HashSet<SinglePrediction>();

    List<File> files = new ArrayList<File>(FileUtils.listFiles(dataDir, new String[] { "libsvm.txt" }, false));

    for (File testFile : files) {
        // create training files from the rest
        Set<File> trainingFiles = new HashSet<File>(files);
        trainingFiles.remove(testFile);/* w ww.j  av  a2 s .  c  om*/

        //            System.out.println("Training files: " + trainingFiles);
        System.out.println("Training files size: " + trainingFiles.size());
        System.out.println("Test file: " + testFile);

        Set<SinglePrediction> predictions = runSingleFold(testFile, new ArrayList<File>(trainingFiles));

        allPredictions.addAll(predictions);
    }

    List<SinglePrediction> predictions = new ArrayList<SinglePrediction>(allPredictions);

    double[][] matrix = new double[predictions.size()][];
    for (int i = 0; i < predictions.size(); i++) {
        SinglePrediction prediction = predictions.get(i);

        matrix[i] = new double[2];
        matrix[i][0] = Double.valueOf(prediction.getGold());
        matrix[i][1] = Double.valueOf(prediction.getPrediction());
    }

    PearsonsCorrelation pearsonsCorrelation = new PearsonsCorrelation(matrix);

    try {
        double pValue = pearsonsCorrelation.getCorrelationPValues().getEntry(0, 1);
        double correlation = pearsonsCorrelation.getCorrelationMatrix().getEntry(0, 1);

        System.out.println("Correlation: " + correlation);
        System.out.println("p-Value: " + pValue);
        System.out.println("Samples: " + predictions.size());

        SpearmansCorrelation sc = new SpearmansCorrelation(new Array2DRowRealMatrix(matrix));
        double pValSC = sc.getRankCorrelation().getCorrelationPValues().getEntry(0, 1);
        double corrSC = sc.getCorrelationMatrix().getEntry(0, 1);

        System.out.println("Spearman: " + corrSC + ", p-Val " + pValSC);
    } catch (MathException e) {
        throw new IOException(e);
    }

}

From source file:com.tunyk.mvn.plugins.htmlcompressor.FileTool.java

public Map<String, String> getFiles() throws IOException {
    Map<String, String> map = new HashMap<String, String>();
    File rootDir = new File(rootDirPath);
    // TODO: fix unchecked warning
    Collection<File> files = FileUtils.listFiles(rootDir, fileExt, recursive);
    int truncationIndex = 0;
    for (File file : files) {
        String normalizedFilePath = file.getCanonicalPath().replaceAll("\\\\", "/");
        if (truncationIndex == 0) {
            truncationIndex = normalizedFilePath.indexOf(rootDirPath) + rootDirPath.length() + 1;
        }/*from   ww w.  ja  va  2 s. c om*/
        String key = normalizedFilePath.substring(truncationIndex);
        String value = FileUtils.readFileToString(file, fileEncoding);
        map.put(key, value);
    }
    return map;
}

From source file:com.alibaba.otter.node.etl.common.io.ArchiveBeanIntegration.java

public void test_pack() {
    ArchiveBean archiveBean = new ArchiveBean();
    try {//w  w w .j  a v a2 s . c  o m
        archiveBean.afterPropertiesSet();
        archiveBean.setUseLocalFileMutliThread(false);
    } catch (Exception e1) {
        want.fail();
    }

    File file = new File("/tmp/otter/test");
    Collection<File> allFiles = FileUtils.listFiles(file, new String[] { "jpg" }, true);

    List<FileData> fileDatas = new ArrayList<FileData>();
    for (File files : allFiles) {
        FileData data = new FileData();
        // data.setPath("wsproduct_repository/product_sku/76/84/32/84/768432847_10.summ.jpg");
        data.setPath(StringUtils.substringAfter(files.getAbsolutePath(), "/tmp/otter/test"));
        fileDatas.add(data);
    }

    File archiveFile = new File("/tmp/otter/test.gzip");
    if (archiveFile.exists()) {
        archiveFile.delete();
    }

    boolean result = archiveBean.pack(archiveFile, fileDatas, new ArchiveRetriverCallback<FileData>() {

        public InputStream retrive(FileData source) {
            return new LazyFileInputStream(new File("/tmp/otter/test", source.getPath()));
        }
    });

    if (!result) {
        want.fail();
    }

}

From source file:com.igormaznitsa.mindmap.plugins.external.ExternalPlugins.java

public void init() {
    final Collection<File> plugins = FileUtils.listFiles(this.pluginsFolder,
            new String[] { PLUGIN_EXTENSION, PLUGIN_EXTENSION.toUpperCase(Locale.ENGLISH) }, false);
    LOGGER.info("Detected " + plugins.size() + " plugin(s)");
    for (final File plugin : plugins) {
        try {//from   w w w.  j a va2s  .  c o  m
            final PluginClassLoader loader = new PluginClassLoader(plugin);
            final String pluginTitle = GetUtils.ensureNonNull(loader.getAttributes(Attribute.TITLE),
                    "<unknown>");
            final Version pluginVersion = new Version(loader.getAttributes(Attribute.VERSION));

            LOGGER.info(String.format("Detected plugin %s [%s]", pluginTitle, pluginVersion.toString()));
            final Version pluginApiVersion = loader.getApiVersion();
            if (this.pluginApiValidator.isValid(pluginApiVersion)) {
                LOGGER.info(String.format("Plugin %s [%s] is valid for API", pluginTitle,
                        pluginVersion.toString()));
                final String[] classes = loader.extractPluginClassNames();
                for (final String klazzName : classes) {
                    LOGGER.info(String.format("Loading plugin class %s from %s", klazzName, pluginTitle));
                    final MindMapPlugin pluginInstance = (MindMapPlugin) loader.loadClass(klazzName)
                            .newInstance();
                    MindMapPluginRegistry.getInstance().registerPlugin(pluginInstance);
                }
            } else {
                LOGGER.warn(String.format("Plugin %s [%s] is not valid for API : %s", pluginTitle,
                        pluginVersion.toString(), pluginApiVersion.toString()));
            }
        } catch (Exception ex) {
            LOGGER.error("Can't load plugin from : " + plugin.getAbsolutePath(), ex);
        }
    }
}

From source file:it.cnr.isti.hlt.processfast.data.RecursiveFileLineIteratorProvider.java

private Collection<File> listFiles(String baseDir, String regexInclusion) {

    Collection<File> files = null;
    if (regexInclusion == null || regexInclusion.isEmpty()) {
        files = FileUtils.listFiles(new File(baseDir), TrueFileFilter.INSTANCE, DirectoryFileFilter.DIRECTORY);
    } else {/* w  w w  . j  av a  2  s  .  c om*/
        files = FileUtils.listFiles(new File(baseDir), new RegexFileFilter(regexInclusion),
                DirectoryFileFilter.DIRECTORY);
    }
    return files;
}

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

@Nonnull
@Override//from w ww  .  j a  v  a  2  s  .com
public FrameworkType check(@Nonnull ProjectDirectory directory) {
    Collection files = FileUtils.listFiles(directory.getDirectory(), new FileExtensionFileFilter("aspx"),
            TrueFileFilter.INSTANCE);

    LOG.info("Got " + files.size() + " .aspx files from the directory.");

    return files.isEmpty() ? FrameworkType.NONE : FrameworkType.DOT_NET_WEB_FORMS;
}