Example usage for java.nio.file Files list

List of usage examples for java.nio.file Files list

Introduction

In this page you can find the example usage for java.nio.file Files list.

Prototype

public static Stream<Path> list(Path dir) throws IOException 

Source Link

Document

Return a lazily populated Stream , the elements of which are the entries in the directory.

Usage

From source file:org.darkware.wpman.config.ReloadableWordpressConfig.java

/**
 * Load all available plugin configuration profile fragments under the given directory. No recursion is done.
 * All profile fragments must end in {@code .yml}.
 *
 * @param themes The {@link ThemeListConfig} to override with the loaded fragments.
 * @param dir The {@link Path} of the directory to scan.
 * @throws IOException If there is an error while listing the directory contents
 *///from w  ww.j a v a2  s . com
protected void loadThemes(final ThemeListConfig themes, final Path dir) throws IOException {
    if (!Files.exists(dir))
        return;
    if (!Files.isDirectory(dir)) {
        WPManager.log.warn("Cannot load theme overrides: {} is not a directory.", dir);
        return;
    }
    if (!Files.isReadable(dir)) {
        WPManager.log.warn("Cannot load theme overrides: {} is not readable.", dir);
        return;
    }

    Files.list(dir).filter(f -> Files.isRegularFile(f)).filter(f -> f.toString().endsWith(".yml"))
            .forEach(f -> this.loadTheme(themes, f));
}

From source file:org.wso2.carbon.identity.recovery.util.Utils.java

public static List<ChallengeQuestion> readChallengeQuestionsFromYAML() throws IdentityRecoveryException {

    List<ChallengeQuestion> challengeQuestionsInAllLocales = new ArrayList<>();
    final boolean[] error = { false };
    try {//from  w ww .j  ava  2s. c  o m
        Files.list(Paths.get(CHALLENGE_QUESTIONS_FOLDER_PATH)).forEach((path) -> {
            try {
                String locale = FilenameUtils.removeExtension(path.toAbsolutePath().toString());
                ChallengeQuestionsFile challengeQuestionFile = FileUtil.readConfigFile(path,
                        ChallengeQuestionsFile.class);
                challengeQuestionFile.getChallengeQuestions().forEach(challengeQuestion -> {
                    challengeQuestion.setLocale(locale);
                });
                challengeQuestionsInAllLocales.addAll(challengeQuestionFile.getChallengeQuestions());
            } catch (IdentityRecoveryException e) {
                log.error(String.format("Error while reading challenge questions from locale file %s", path));
                error[0] = true;
            }
        });
    } catch (IOException e) {
        throw new IdentityRecoveryException("Error while reading challenge questions", e);
    }

    if (error[0]) {
        throw new IdentityRecoveryException("Error while updating challenge questions");
    }

    return challengeQuestionsInAllLocales;
}

From source file:org.apache.archiva.indexer.maven.MavenIndexManagerTest.java

@Test
public void createContext() throws Exception {
    ArchivaIndexingContext ctx = createTestContext();
    assertNotNull(ctx);/*from w  w  w . j a v  a2 s .c om*/
    assertEquals(repository, ctx.getRepository());
    assertEquals("test-repo", ctx.getId());
    assertEquals(indexPath.toAbsolutePath(), Paths.get(ctx.getPath()).toAbsolutePath());
    assertTrue(Files.exists(indexPath));
    List<Path> li = Files.list(indexPath).collect(Collectors.toList());
    assertTrue(li.size() > 0);

}

From source file:net.morimekta.idltool.IdlUtils.java

public static Map<String, String> buildSha1Sums(Path dir) throws IOException {
    ImmutableSortedMap.Builder<String, String> sha1sums = ImmutableSortedMap.naturalOrder();

    // TODO: Support nested directories.
    Files.list(dir).forEach(file -> {
        try {//w  w w  .  j  av a  2s . co m
            if (Files.isRegularFile(file)) {
                String sha = DigestUtils.sha1Hex(Files.readAllBytes(file));
                sha1sums.put(file.getFileName().toString(), sha);
            }
        } catch (IOException e) {
            throw new UncheckedIOException(e.getMessage(), e);
        }
    });

    return sha1sums.build();
}

From source file:org.wildfly.core.test.standalone.mgmt.api.ModelPersistenceTestCase.java

private CfgFileDescription getLatestBackup(Path dir) throws IOException {

    final int[] lastVersion = { 0 };
    final File[] lastFile = { null };

    if (Files.isDirectory(dir)) {
        try (Stream<Path> files = Files.list(dir)) {
            files.filter(file -> {/*ww w.  j a v a 2  s .  co m*/
                String fileName = file.getFileName().toString();
                String[] nameParts = fileName.split("\\.");
                return !(!nameParts[0].contains("standalone") && !nameParts[2].equals("xml"));
            }).forEach(path -> {
                String fileName = path.getFileName().toString();
                String[] nameParts = fileName.split("\\.");
                if (!nameParts[0].contains("standalone")) {
                    return;
                }
                if (!nameParts[2].equals("xml")) {
                    return;
                }
                int version = Integer.valueOf(nameParts[1].substring(1));
                if (version > lastVersion[0]) {
                    lastVersion[0] = version;
                    lastFile[0] = path.toFile();
                }
            });
        }
    }
    return new CfgFileDescription(lastVersion[0], lastFile[0],
            (lastFile[0] != null) ? FileUtils.checksumCRC32(lastFile[0]) : 0);
}

From source file:software.coolstuff.springframework.owncloud.service.impl.local.OwncloudLocalResourceServiceImpl.java

private List<OwncloudResource> getDirectoryResources(Path location) {
    try {/*w  ww  .jav  a2  s. c  o m*/
        List<OwncloudResource> owncloudResources = new ArrayList<>();
        owncloudResources.add(getActualDirectoryOf(location));
        try (Stream<Path> stream = Files.list(location)) {
            stream.map(this::createOwncloudResourceOf)
                    .peek(resource -> log.debug("Add Resource {} to the Result", resource.getHref()))
                    .forEach(owncloudResources::add);
        }
        getParentDirectoryOf(location).ifPresent(owncloudResources::add);
        return owncloudResources;
    } catch (IOException e) {
        throw new OwncloudLocalResourceException(e);
    }
}

From source file:org.objectpocket.storage.blob.MultiZipBlobStore.java

private void createIndexFromBlobContainer(Path path, String blobContainerName) throws IOException {
    Stream<Path> list = Files.list(path);
    Iterator<Path> iterator = list.iterator();
    while (iterator.hasNext()) {
        Path p = iterator.next();
        if (Files.isDirectory(p)) {
            createIndexFromBlobContainer(p, blobContainerName);
        } else {//from   w w  w . j av  a2 s.c om
            // substring(1) removes first /
            blobContainerIndex.put(p.toString().substring(1), blobContainerName);
        }
    }
    list.close();
}

From source file:org.wso2.carbon.launcher.test.OSGiLibBundleDeployerTest.java

private static void delete(Path path) throws IOException {
    Path osgiRepoPath = Paths.get(carbonHome, Constants.OSGI_REPOSITORY);
    Files.list(path).filter(child -> !osgiRepoPath.equals(child) && Files.isDirectory(child)).forEach(child -> {
        try {/* ww w  .  j ava2  s  .  co  m*/
            FileUtils.deleteDirectory(child.toFile());
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    });
}

From source file:org.roda.core.plugins.misc.RodaFolderAIP.java

/**
 * Find other metadata files and for each one calls
 * {@link IPMetadataSetter#addMetadata(IPMetadata)}.
 *
 * @param omdPath/*from  w  w w .ja va2s.  co  m*/
 *          the {@link Path} to other metadata files.
 * @param mdSetter
 *          the {@link IPMetadataSetter}.
 * @throws IOException
 *           if some I/O error occurs.
 * @throws IPException
 *           if some other error occurs.
 */
private void findAndAddOtherMDs(final Path omdPath, final IPMetadataSetter mdSetter)
        throws IOException, IPException {
    if (FSUtils.isDirectory(omdPath)) {
        final Iterator<Path> paths = Files.list(omdPath).iterator();
        while (paths.hasNext()) {
            final Path mdPath = paths.next();
            if (FSUtils.isDirectory(mdPath)) {
                for (IPMetadata md : findMDs(mdPath,
                        MetadataType.OTHER().setOtherType(mdPath.getFileName().toString()))) {
                    mdSetter.addMetadata(md);
                }
            }
            if (FSUtils.isFile(mdPath)) {
                for (IPMetadata md : findMDs(mdPath, MetadataType.OTHER())) {
                    mdSetter.addMetadata(md);
                }
            }
        }
    }
}

From source file:org.apache.hadoop.hbase.tool.coprocessor.CoprocessorValidator.java

private List<URL> buildClasspath(List<String> jars) throws IOException {
    List<URL> urls = new ArrayList<>();

    for (String jar : jars) {
        Path jarPath = Paths.get(jar);
        if (Files.isDirectory(jarPath)) {
            try (Stream<Path> stream = Files.list(jarPath)) {
                List<Path> files = stream.filter((path) -> Files.isRegularFile(path))
                        .collect(Collectors.toList());

                for (Path file : files) {
                    URL url = file.toUri().toURL();
                    urls.add(url);/*from ww w.ja  v  a2s.  c  om*/
                }
            }
        } else {
            URL url = jarPath.toUri().toURL();
            urls.add(url);
        }
    }

    return urls;
}