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:de.systemoutprintln.junit4examples.rules.TemporaryFolderRuleTest.java

@Test
public void createTempFolder() throws IOException {
    // the same works for dirs... nice!
    tempFolder = folder.newFolder("tmp");
    File childFile = new File(tempFolder, "child.txt");
    childFile.createNewFile();// w  ww .j a  va  2s  .co  m

    @SuppressWarnings("unchecked")
    Collection<File> containedFiles = FileUtils.listFiles(tempFolder, new String[] { "txt" }, false);

    assertThat(containedFiles, hasItem(childFile));
}

From source file:gemlite.core.internal.support.hotdeploy.scanner.ScannerIterator.java

public ScannerIterator(URL url) throws IOException, URISyntaxException {
    if (url.getProtocol().equals("http") || url.getFile().endsWith(".jar")) {
        jarFile = true;/*from  w  w  w.ja va  2 s  . c om*/
        jarInputStream = new JarInputStream(url.openStream());
    } else {
        Collection<File> colls = FileUtils.listFiles(new File(url.toURI()),
                new String[] { class_suffix.substring(1) }, true);
        classFileIterator = colls.iterator();
        classpathLen = url.getFile().length();
    }

}

From source file:adalid.util.i18n.Mapper.java

private boolean map() {
    File rootFolder = PropertiesHandler.getRootFolder();
    if (FilUtils.isNotVisibleDirectory(rootFolder)) {
        return false;
    }// w  ww  .ja v a2s  .  c  o m
    String projectSource = rootFolder.getPath() + FILE_SEPARATOR + _project + FILE_SEPARATOR + "source";
    File projectSourceFile = new File(projectSource);
    if (FilUtils.isNotVisibleDirectory(projectSourceFile)) {
        return false;
    }
    RegexFileFilter fileFilter = new RegexFileFilter("^Bundle.*\\.properties$");
    RegexFileFilter dirFilter1 = new RegexFileFilter("build");
    RegexFileFilter dirFilter2 = new RegexFileFilter("velocity");
    IOFileFilter notFileFilter = FileFilterUtils.notFileFilter(FileFilterUtils.or(dirFilter1, dirFilter2));
    Collection<File> bundles = FileUtils.listFiles(projectSourceFile, fileFilter, notFileFilter);
    String base;
    List<File> list;
    for (File bundle : bundles) {
        base = base(bundle);
        if (_map.containsKey(base)) {
            list = _map.get(base);
        } else {
            list = new ArrayList<>();
            _map.put(base, list);
        }
        list.add(bundle);
    }
    return true;
}

From source file:de.burlov.amazon.s3.dirsync.test.TestDirSync.java

private boolean compareFolders(File dir1, File dir2) throws IOException {
    long crc1 = 0;
    for (File file : (Collection<File>) FileUtils.listFiles(dir1, FileFilterUtils.trueFileFilter(),
            FileFilterUtils.trueFileFilter())) {
        if (file.isFile()) {
            crc1 += FileUtils.checksumCRC32(file);
        }/* w  ww  .j ava2s.  c o  m*/
    }
    long crc2 = 0;
    for (File file : (Collection<File>) FileUtils.listFiles(dir2, FileFilterUtils.trueFileFilter(),
            FileFilterUtils.trueFileFilter())) {
        if (file.isFile()) {
            crc2 += FileUtils.checksumCRC32(file);
        }
    }
    return crc1 == crc2;
}

From source file:lineage2.gameserver.skills.SkillsEngine.java

/**
 * Method loadAllSkills.//from w ww .  j a  v a 2 s . co m
 * @return Map<Integer,Skill>
 */
public Map<Integer, Skill> loadAllSkills() {
    File dir = new File(Config.DATAPACK_ROOT, "data/xml/stats/skills");
    if (!dir.exists()) {
        _log.info("Dir " + dir.getAbsolutePath() + " not exists");
        return Collections.emptyMap();
    }
    Collection<File> files = FileUtils.listFiles(dir, FileFilterUtils.suffixFileFilter(".xml"),
            FileFilterUtils.directoryFileFilter());
    Map<Integer, Skill> result = new HashMap<>();
    int maxId = 0, maxLvl = 0;
    for (File file : files) {
        List<Skill> s = loadSkills(file);
        if (s == null) {
            continue;
        }
        for (Skill skill : s) {
            result.put(SkillTable.getSkillHashCode(skill), skill);
            if (skill.getId() > maxId) {
                maxId = skill.getId();
            }
            if (skill.getLevel() > maxLvl) {
                maxLvl = skill.getLevel();
            }
        }
    }
    _log.info("SkillsEngine: Loaded " + result.size() + " skill templates from XML files. Max id: " + maxId
            + ", max level: " + maxLvl);
    return result;
}

From source file:eumetsat.pn.elasticsearch.ElasticsearchFeeder.java

protected void indexDirContent(Path aSrcDir) {
    log.info("Indexing dir content {}", aSrcDir);

    JSONParser parser = new JSONParser();

    YamlNode endpointConfig = this.config.get("endpoint");

    log.info("Endpoint configuration: {}", endpointConfig);

    Settings settings = ImmutableSettings.settingsBuilder()
            .put("cluster.name", endpointConfig.get("cluster.name").asTextValue()).build();

    try (TransportClient client = new TransportClient(settings);) {
        client.addTransportAddress(new InetSocketTransportAddress(endpointConfig.get("host").asTextValue(),
                endpointConfig.get("port").asIntValue()));
        int cpt = 0;
        Collection<File> inputFiles = FileUtils.listFiles(aSrcDir.toFile(), new String[] { "json" }, false);
        log.info("Indexing {} files...", inputFiles.size());

        for (File file : inputFiles) {

            try {
                String jsonStr = FileUtils.readFileToString(file);
                JSONObject jsObj = (JSONObject) parser.parse(jsonStr);

                String index = endpointConfig.get("index").asTextValue();
                String type = endpointConfig.get("type").asTextValue();

                String id = (String) jsObj.get(FILE_IDENTIFIER_PROPERTY);
                log.debug("Adding {} (type: {}) to {}", id, type, index);
                IndexResponse response = client.prepareIndex(index, type, id).setSource(jsObj.toJSONString())
                        .execute().actionGet();

                cpt++;/*from   ww w .ja v  a  2s . c  om*/

                if (response.isCreated()) {
                    log.trace("Response: {} | version: {}", response.getId(), response.getVersion());
                } else {
                    log.warn("NOT created! ResponseResponse: {}", response.getId());
                }
            } catch (IOException | ParseException e) {
                log.error("Error with json file ", file, e);
            }
        }

        log.info("Indexed {} of {} files.", cpt, inputFiles.size());
    } catch (RuntimeException e) {
        log.error("Error indexing json files.", e);
    }
}

From source file:com.thoughtworks.go.server.service.RailsAssetsService.java

public void initialize() throws IOException {
    if (!systemEnvironment.useCompressedJs()) {
        return;/*from   w w w  . j  a v a2 s  . c  o  m*/
    }
    String assetsDirPath = servletContext
            .getRealPath(servletContext.getInitParameter("rails.root") + "/public/assets/");
    File assetsDir = new File(assetsDirPath);
    if (!assetsDir.exists()) {
        throw new RuntimeException(String.format("Assets directory does not exist %s", assetsDirPath));
    }
    Collection files = FileUtils.listFiles(assetsDir, new RegexFileFilter(MANIFEST_FILE_PATTERN), null);
    if (files.isEmpty()) {
        throw new RuntimeException(String.format("Manifest json file was not found at %s", assetsDirPath));
    }

    File manifestFile = (File) files.iterator().next();

    LOG.info("Found rails assets manifest file named {} ", manifestFile.getName());
    String manifest = FileUtils.readFileToString(manifestFile, UTF_8);
    Gson gson = new Gson();
    railsAssetsManifest = gson.fromJson(manifest, RailsAssetsManifest.class);
    LOG.info("Successfully read rails assets manifest file located at {}", manifestFile.getAbsolutePath());
}

From source file:com.topekalabs.java.utils.ClassUtils.java

public static Collection<File> getClassFiles(File srcDirectory, String className) {
    notClassNameException(className);/*from  w w w.  ja v  a2s.  c  om*/

    return FileUtils.listFiles(srcDirectory,
            new IOFileFilterRegexName(Pattern.quote(className + CLASS_FILE_SUFFIX)), TrueFileFilter.INSTANCE);
}

From source file:com.liferay.mobile.sdk.core.tests.MobileSDKCoreTests.java

private Collection<File> build(String server, String contextName, String filter, String packageName)
        throws IOException {
    final File newTempDir = MobileSDKCore.newTempDir();

    MobileSDKBuilder.build(server, contextName, packageName, filter, newTempDir.getCanonicalPath(),
            new NullProgressMonitor());

    return FileUtils.listFiles(newTempDir, null, true);
}

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

@Test
public void testSaveThenLoad() throws Exception {
    Collection<FpqEntry> entries = new LinkedList<FpqEntry>();
    entries.add(new FpqEntry(idGen.incrementAndGet(), new byte[] { 0, 1, 2 }));
    entries.add(new FpqEntry(idGen.incrementAndGet(), new byte[] { 3, 4, 5 }));
    entries.add(new FpqEntry(idGen.incrementAndGet(), new byte[] { 6, 7, 8 }));

    MemorySegment seg1 = new MemorySegment();
    seg1.setId(new UUID());
    seg1.setMaxSizeInBytes(1000);/*from   w w w  .  ja va  2  s .  com*/
    seg1.setStatus(MemorySegment.Status.READY);
    seg1.push(entries, 10);

    serializer.saveToDisk(seg1);

    Collection<File> files = FileUtils.listFiles(theDir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
    assertThat(files.size(), is(1));

    MemorySegment seg2 = serializer.loadFromDisk(files.iterator().next().getName());
    assertThat(seg2.getId(), is(seg1.getId()));
    assertThat(seg2.getQueue().size(), is(seg1.getQueue().size()));
    assertThat(seg2.getMaxSizeInBytes(), is(1000L));
    assertThat(seg2.getNumberOfOnlineEntries(), is(3L));
    assertThat(seg2.getNumberOfEntries(), is(3L));
}