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.jstar.eclipse.services.JStar.java

@SuppressWarnings("static-access")
// in io 2.0 FileUtils.listFiles should return Collection<File> instead of Collection
public List<File> convertToJimple(final JavaFile fileToConvert) {
    String fileDirectory = fileToConvert.getOutputDirectory().getLocation().toOSString();
    String javaFile = fileToConvert.getNameWithPackage();

    final String sootOutput = fileDirectory + File.separator + SootOutput + File.separator + javaFile;

    final String[] args = { "-cp",
            PreferenceConstants.getSootClassPath() + File.pathSeparator + fileToConvert.getProjectClasspath(),
            "-f", "J", "-output-dir", sootOutput, "-src-prec", "java",
            //"-v",
            "-print-tags", javaFile };

    soot.G.v().reset();//w ww .ja v a2 s.c om
    soot.Main.main(args);

    final List<String> types = fileToConvert.getTypes();
    final List<File> jimpleFiles = new LinkedList<File>();

    for (Object file : (FileUtils.listFiles(new File(sootOutput), new WildcardFileFilter("*.jimple"), null))) {
        final String fileName = ((File) file).getName();

        if (types.indexOf(new Path(fileName).removeFileExtension().toOSString()) != -1) {
            jimpleFiles.add((File) file);
        }
    }

    if (jimpleFiles == null || jimpleFiles.size() == 0) {
        ConsoleService.getInstance()
                .printErrorMessage("An error occurred while converting java file to jimple format.");
        throw new NullPointerException();
    }

    return jimpleFiles;
}

From source file:com.mirth.connect.cli.launcher.CommandLineLauncher.java

private static void addSharedLibsToClasspath(List<URL> urls) throws Exception {
    IOFileFilter sharedLibFileFilter = new WildcardFileFilter("*-shared.jar");
    File extensions = new File("./extensions");

    if (extensions.exists() && extensions.isDirectory()) {
        Collection<File> sharedLibs = FileUtils.listFiles(extensions, sharedLibFileFilter,
                FileFilterUtils.trueFileFilter());

        for (File sharedLib : sharedLibs) {
            logger.trace("adding library to classpath: " + sharedLib.getAbsolutePath());
            urls.add(sharedLib.toURI().toURL());
        }//www. j a va 2  s  . co m
    } else {
        logger.warn("no extensions found");
    }
}

From source file:com.maxl.java.aips2sqlite.PseudoExpertInfo.java

public int process() {
    try {// ww  w.j ava  2  s.co m
        File dir = new File(FILE_PSEUDO_INFO_DIR);
        if (dir != null && dir.isDirectory()) {
            Collection<File> files = FileUtils.listFiles(dir, FileFilterUtils.suffixFileFilter(".docx"),
                    TrueFileFilter.INSTANCE);
            if (files != null) {
                System.out.println("\nProcessing total of " + files.size() + " pseudo Fachinfos...");
                int idxPseudo = 1;
                for (File pseudo : files) {
                    if (pseudo.isFile()) {
                        FileInputStream pseudoInfoFile = new FileInputStream(pseudo.getAbsoluteFile());
                        if (extractInfo(idxPseudo, pseudoInfoFile))
                            idxPseudo++;
                    }
                }
                return idxPseudo - 1;
            }
        } else {
            System.out.println("Directory with pseudo FIs not found!");
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return 0;
    }
    return 0;
}

From source file:com.silverpeas.wiki.WikiInstanciatorTest.java

/**
 * Test of createPages method, of class WikiInstanciator.
 *//*from   w  w w .  j a  va2 s.c  om*/
@Test
public void testCreatePages() throws Exception {
    String instanceId = "wiki18";
    WikiPageDAO dao = mock(WikiPageDAO.class);
    WikiInstanciator instance = new WikiInstanciator(dao);
    File directory = folder.newFolder("Test de base");
    FileUtils.forceDeleteOnExit(directory);
    PageDetail aboutPage = new PageDetail();
    aboutPage.setInstanceId(instanceId);
    aboutPage.setPageName("About");
    PageDetail approvalRequiredForPageChanges = new PageDetail();
    approvalRequiredForPageChanges.setInstanceId(instanceId);
    approvalRequiredForPageChanges.setPageName("ApprovalRequiredForPageChanges");

    instance.createPages(directory, instanceId);
    assertNotNull(directory);
    verify(dao).createPage(aboutPage);
    verify(dao).createPage(approvalRequiredForPageChanges);

    Collection uncompressedFiles = FileUtils.listFiles(directory, new String[] { "txt" }, true);
    assertNotNull(uncompressedFiles.size());
    assertEquals(29, uncompressedFiles.size());

}

From source file:de.flapdoodle.embed.process.store.ExtractedArtifactStore.java

@Override
public IExtractedFileSet extractFileSet(Distribution distribution) throws IOException {
    File artifact = LocalArtifactStore.getArtifact(_downloadConfig, distribution);
    File directory = getTargetDirectoryForExtractedFiles(artifact);

    FileSet fileSet = _packageResolver.getFileSet(distribution);

    Map<FileSet.Entry, File> matchingFiles = findMatchingFiles(fileSet,
            FileUtils.listFiles(directory, null, true));
    List<FileSet.Entry> missingEntries = getMissingEntries(fileSet, matchingFiles.keySet());

    if (missingEntries.isEmpty()) {
        return extractFileSet(matchingFiles, directory);
    }/*w  ww. j a v  a  2 s.c  o m*/

    IExtractor extractor = Extractors.getExtractor(_packageResolver.getArchiveType(distribution));
    return extractFileSet(artifact, directory, fileSet, extractor);
}

From source file:com.aionemu.commons.utils.PropertiesUtils.java

/**
 * Loads all .property files form directory
 *
 * @param dir       directory//from w ww.  j  ava2 s.  c om
 * @param recursive parse subdirectories or not
 * @return array of loaded properties
 * @throws IOException if was unable to read properties
 */
@SuppressWarnings("unchecked")
public static Properties[] loadAllFromDirectory(File dir, boolean recursive) throws IOException {
    Collection<File> files = FileUtils.listFiles(dir, new String[] { "properties" }, recursive);
    return load(files.toArray(new File[files.size()]));
}

From source file:com.ning.arecibo.util.timeline.persistent.Replayer.java

public int readAll(final boolean deleteFiles, final @Nullable DateTime minStartTime,
        final Function<HostSamplesForTimestamp, Void> fn) {
    final Collection<File> files = FileUtils.listFiles(new File(path), new String[] { "bin" }, false);
    int filesSkipped = 0;
    for (final File file : FILE_ORDERING.sortedCopy(files)) {
        try {/*  w  w w .j  a  va 2s .co  m*/
            // Skip files whose last modification date is is earlier than the first start time.
            if (minStartTime != null && file.lastModified() < minStartTime.getMillis()) {
                filesSkipped++;
                continue;
            }
            read(file, fn);
            if (shuttingDown.get()) {
                break;
            }

            if (deleteFiles) {
                if (!file.delete()) {
                    log.warn("Unable to delete file: {}", file.getAbsolutePath());
                }
            }
        } catch (IOException e) {
            log.warn("Exception replaying file: {}", file.getAbsolutePath(), e);
        }
    }
    return filesSkipped;
}

From source file:com.hurence.logisland.processor.DetectOutliersTest.java

@Test
@Ignore("too long")
public void testDetection() throws IOException {
    final TestRunner testRunner = TestRunners.newTestRunner(new DetectOutliers());
    testRunner.setProperty(DetectOutliers.ROTATION_POLICY_TYPE, "by_amount");
    testRunner.setProperty(DetectOutliers.ROTATION_POLICY_AMOUNT, "100");
    testRunner.setProperty(DetectOutliers.ROTATION_POLICY_UNIT, "points");
    testRunner.setProperty(DetectOutliers.CHUNKING_POLICY_TYPE, "by_amount");
    testRunner.setProperty(DetectOutliers.CHUNKING_POLICY_AMOUNT, "10");
    testRunner.setProperty(DetectOutliers.CHUNKING_POLICY_UNIT, "points");
    testRunner.setProperty(DetectOutliers.GLOBAL_STATISTICS_MIN, "-100000");
    testRunner.setProperty(DetectOutliers.MIN_AMOUNT_TO_PREDICT, "100");
    testRunner.setProperty(DetectOutliers.ZSCORE_CUTOFFS_NORMAL, "3.5");
    testRunner.setProperty(DetectOutliers.ZSCORE_CUTOFFS_MODERATE, "5");

    testRunner.setProperty(DetectOutliers.RECORD_VALUE_FIELD, "value");
    testRunner.setProperty(DetectOutliers.RECORD_TIME_FIELD, "timestamp");
    testRunner.assertValid();/*  w ww  . j av a 2 s.co m*/

    File f = new File(RESOURCES_DIRECTORY);

    Pair<Integer, Integer>[] results = new Pair[] { new Pair(4032, 124), new Pair(4032, 8), new Pair(4032, 315),
            new Pair(4032, 0), new Pair(4032, 29), new Pair(4032, 2442), new Pair(4032, 314),
            new Pair(4032, 296)

    };

    int count = 0;
    for (File file : FileUtils.listFiles(f, new SuffixFileFilter(".csv"), TrueFileFilter.INSTANCE)) {

        if (count >= results.length)
            break;

        BufferedReader reader = Files.newBufferedReader(file.toPath(), ENCODING);
        List<Record> records = TimeSeriesCsvLoader.load(reader, true, inputDateFormat);
        Assert.assertTrue(!records.isEmpty());

        testRunner.clearQueues();
        testRunner.enqueue(records.toArray(new Record[records.size()]));
        testRunner.run();
        testRunner.assertAllInputRecordsProcessed();

        System.out.println("records.size() = " + records.size());
        System.out.println("testRunner.getOutputRecords().size() = " + testRunner.getOutputRecords().size());
        testRunner.assertOutputRecordsCount(results[count].getSecond());
        count++;

    }

}

From source file:io.lightlink.utils.ClasspathScanUtils.java

private static void findFromDirectory(URL packageURL, List<String> names) throws UnsupportedEncodingException {
    if (packageURL == null)
        return;/*from  w  ww. j a va2s  .  co m*/
    File folder = new File(URLDecoder.decode(packageURL.getPath(), "UTF-8"));

    Collection<File> files = FileUtils.listFiles(folder, null, true);
    int length = folder.getAbsolutePath().length();

    String entryName;
    if (files != null)
        for (File actual : files) {
            entryName = actual.getAbsolutePath().substring(length);
            names.add(entryName);
        }
}

From source file:com.thruzero.common.jsf.support.beans.dialog.AbstractAboutApplicationBean.java

public String getJarRows() {
    StringBuffer result = new StringBuffer();

    try {/*from w w w  .j  av a 2  s .co m*/
        File webInfDir = FacesUtils.getWebInfDir();
        if (webInfDir != null) {
            File libDir = new File(webInfDir, "lib");
            String[] extensions = { "jar" };
            @SuppressWarnings("unchecked") // FileUtils isn't generic
            Collection<File> jarFiles = FileUtils.listFiles(libDir, extensions, false);
            StringMap aboutLibs = ConfigLocator.locate()
                    .getSectionAsStringMap(AboutBoxConfigKeys.ABOUT_LIBS_SECTION);

            if (aboutLibs == null) {
                result.append("<br/><span style=\"color:red;\">The " + AboutBoxConfigKeys.ABOUT_LIBS_SECTION
                        + " config section was not found.</span>");
            } else {
                for (File jarFile : jarFiles) {
                    String version = StringUtils.substringAfterLast(jarFile.getName(), "-");
                    version = StringUtils.remove(version, ".jar");
                    String aboutKey = StringUtils.substringBeforeLast(jarFile.getName(), "-");

                    // make sure it's the full version number (e.g., "hibernate-c3p0-3.5.0-Final" at this point will be "Final". Need to back up a segment to get the version number.
                    String versComp = StringUtils.substringBefore(version, ".");
                    if (!StringUtils.isNumeric(versComp)) {
                        String version2 = StringUtils.substringAfterLast(aboutKey, "-");
                        versComp = StringUtils.substringBefore(version2, ".");
                        if (StringUtils.isNumeric(versComp)) {
                            aboutKey = StringUtils.substringBeforeLast(aboutKey, "-");
                            version = version2 + "-" + version;
                        } else {
                            continue; // give up on this one
                        }
                    }

                    // get config value for this jar file
                    if (StringUtils.isNotEmpty(aboutKey) && StringUtils.isNotEmpty(version)
                            && aboutLibs.containsKey(aboutKey)) {
                        String href = aboutLibs.get(aboutKey);
                        aboutKey = StringUtils.remove(aboutKey, "-core");
                        result.append(TableUtils.createSimpleFormRow(aboutKey, href, version));
                    }
                }
            }
        }
    } catch (Exception e) {
        // don't let the about box crash the app
    }

    return result.toString();
}