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.wso2.carbon.uuf.internal.io.ArtifactComponentReference.java

@Override
public Stream<FragmentReference> getFragments(Set<String> supportedExtensions) {
    Path fragments = componentDirectory.resolve(DIR_NAME_FRAGMENTS);
    if (!Files.exists(fragments)) {
        return Stream.<FragmentReference>empty();
    }/*  w ww  .  j a  va 2  s.  c om*/
    try {
        return Files.list(fragments).filter(Files::isDirectory)
                .map(path -> new ArtifactFragmentReference(path, this, supportedExtensions));
    } catch (IOException e) {
        throw new FileOperationException("An error occurred while listing fragments in '" + fragments + "'.",
                e);
    }
}

From source file:org.apache.storm.localizer.LocalizedResource.java

static Collection<String> getLocalizedUsers(Path localBaseDir) throws IOException {
    Path userCacheDir = getUserCacheDir(localBaseDir);
    if (!Files.exists(userCacheDir)) {
        return Collections.emptyList();
    }/*from  w w  w.ja  v a 2  s.  com*/
    return Files.list(userCacheDir).map((p) -> p.getFileName().toString()).collect(Collectors.toList());
}

From source file:org.trellisldp.file.FileUtils.java

/**
 * Fetch a stream of files in the provided directory path.
 * @param path the directory path// w w  w . j a  va2 s  . c  o  m
 * @return a stream of filenames
 */
public static Stream<Path> uncheckedList(final Path path) {
    try {
        return Files.list(path);
    } catch (final IOException ex) {
        throw new UncheckedIOException("Error fetching file list", ex);
    }
}

From source file:org.zanata.sync.jobs.cache.RepoCache.java

default Optional<Path> getCachedRepo(Path rootCacheDir, String url) {
    Path expected = cacheDirForRepo(rootCacheDir, url);
    boolean exists = Files.exists(expected);
    if (exists && Files.isDirectory(expected)) {
        try (Stream<Path> subPaths = Files.list(expected)) {
            if (subPaths.count() > 0) {
                return Optional.of(expected);
            }//  w  w  w . ja v a 2s .com
        } catch (IOException e) {
            log.warn("error reading cached repo folder: " + expected, e);
            return Optional.empty();
        }
    }
    return Optional.empty();
}

From source file:org.talend.dataprep.folder.store.file.FileSystemFolderRepository.java

@Override
public Iterable<Folder> children(String parentId) {
    final FolderPath parentDpPath = fromId(parentId);
    try {// w  w w  . j a  va  2s  . c o m
        Path folderPath;
        if (parentDpPath != null) {
            folderPath = pathsConverter.toPath(parentDpPath);
        } else {
            folderPath = pathsConverter.getRootFolder();
        }
        List<Folder> children;
        if (Files.notExists(folderPath)) {
            children = emptyList();
        } else {
            try (Stream<Path> childrenStream = Files.list(folderPath)) {
                children = childrenStream //
                        .map(p -> toFolderIfDirectory(p, security.getUserId())) //
                        .filter(Objects::nonNull) //
                        .collect(toList());
            }
        }
        return children;
    } catch (IOException e) {
        throw new TDPException(UNABLE_TO_LIST_FOLDER_CHILDREN, e,
                build().put("path", parentDpPath == null ? null : parentDpPath.serializeAsString()));
    }
}

From source file:it.greenvulcano.configuration.BaseConfigurationManager.java

@Override
public Set<File> getHistory() throws IOException {
    Path history = getHistoryPath();
    if (Files.exists(history)) {

        Path currentConfigArchive = getConfigurationPath(getCurrentConfigurationName());
        Predicate<Path> currentConfig = p -> {
            try {
                return Files.isSameFile(p, currentConfigArchive);
            } catch (IOException e) {
                return false;
            }/*from  www  . ja va 2s  .  c  o  m*/
        };

        return Files.list(history).filter(currentConfig.negate()).map(Path::toFile).collect(Collectors.toSet());
    }

    return new LinkedHashSet<>();
}

From source file:edu.umd.umiacs.clip.tools.io.AllFiles.java

public static Stream<File> list(Path dir) {
    try {//  w w  w .  jav  a2s  .  co m
        return Files.list(dir).map(Path::toFile);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:ubicrypt.core.S3DownloadIT.java

@Test
public void downloadFiles() throws Exception {
    if (StringUtils.isEmpty(System.getenv("aws.accessKey"))) {
        return;//from   ww  w .j  ava 2  s . c o  m
    }
    CountDownLatch cd = new CountDownLatch(1);
    Subscription sub = appEvents.subscribe(event -> {
        if (event instanceof SynchDoneEvent) {
            cd.countDown();
        }
    });
    assertThat(cd.await(20, TimeUnit.SECONDS)).isTrue();
    sub.unsubscribe();
    assertThat(Files.list(TestUtils.tmp2)).hasSize(nfiles);
    S3Provider provider = (S3Provider) providerLifeCycle.currentlyActiveProviders().get(0).getProvider();
    provider.getClient().listObjects("test-gfrison").getObjectSummaries().stream().forEach(
            s3ObjectSummary -> provider.getClient().deleteObject("test-gfrison", s3ObjectSummary.getKey()));
}

From source file:org.xlrnet.tibaija.tools.fontgen.FontgenApplication.java

@NotNull
private Font importFont(String source, String fontIdentifier) throws IOException {
    Path sourcePath = Paths.get(source);

    Pattern filePattern = Pattern.compile("[0-9A-F]{2}h_" + fontIdentifier + "[a-zA-Z0-9]*.gif");

    List<Path> fileList = Files.list(sourcePath)
            .filter(p -> filePattern.matcher(p.getFileName().toString()).matches())
            .collect(Collectors.toList());

    Font font = new Font();
    List<Symbol> symbols = new ArrayList<>();

    for (Path path : fileList) {
        try {/* w  ww.j  a v  a2s .c  o  m*/
            Symbol symbol = importFile(path, font, fontIdentifier);

            if (symbol == null)
                continue;

            String filename = path.getFileName().toString();
            String hexValue = StringUtils.substring(filename, 0, 2);
            String internalIdentifier = StringUtils.substringBetween(filename, "_" + fontIdentifier, ".gif");

            symbol.setHexValue(hexValue);
            symbol.setInternalIdentifier(internalIdentifier);

            symbols.add(symbol);
        } catch (ImageReadException e) {
            LOGGER.error("Reading image {} failed", path.toAbsolutePath(), e);
        }
    }

    Collections.sort(symbols);
    font.setSymbols(symbols);

    return font;
}

From source file:com.github.horrorho.inflatabledonkey.chunk.store.disk.DiskChunkStoreTest.java

@Ignore
@Test//from   www.j a  va2  s . c o  m
@Parameters
public void test(byte[] data) throws IOException {
    Supplier<Digest> digests = SHA1Digest::new;
    DiskChunkStore store = new DiskChunkStore(digests, ChunkDigests::test, CACHE, TEMP);

    byte[] checksum = digest(digests, data);
    Optional<OutputStream> chunkOutputStream = store.outputStream(checksum);
    assertTrue("OutputStream present", chunkOutputStream.isPresent());

    try (OutputStream os = chunkOutputStream.get()) {
        os.write(data);
    }
    Optional<Chunk> chunkData = store.chunk(checksum);
    assertTrue("Chunk present", chunkData.isPresent());

    Chunk chunk = chunkData.get();
    assertArrayEquals("checksum match", checksum, chunk.checksum());

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try (InputStream is = chunk.inputStream().orElseThrow(() -> new IllegalStateException("chunk deleted"))) {
        IOUtils.copy(is, baos);
    }
    assertArrayEquals("data match", data, baos.toByteArray());

    Optional<OutputStream> duplicateOutputStream = store.outputStream(checksum);
    assertFalse("duplicate OutputStream not present", duplicateOutputStream.isPresent());

    boolean isDeleted = store.delete(checksum);
    assertTrue("was deleted", isDeleted);

    Optional<Chunk> deleted = store.chunk(checksum);
    assertFalse(deleted.isPresent());

    assertFalse("temp folder is empty", Files.list(TEMP).findFirst().isPresent());
}