Search in sources :

Example 1 with CombiningIterator

use of org.neo4j.internal.helpers.collection.CombiningIterator in project neo4j by neo4j.

the class EphemeralFileSystemAbstraction method listFiles.

@Override
public Path[] listFiles(Path directory) throws IOException {
    directory = canonicalFile(directory);
    if (files.containsKey(directory)) {
        throw new NotDirectoryException(directory.toString());
    }
    if (!directories.contains(directory)) {
        throw new NoSuchFileException(directory.toString());
    }
    Set<Path> found = new HashSet<>();
    Iterator<Path> filesAndFolders = new CombiningIterator<>(asList(this.files.keySet().iterator(), directories.iterator()));
    while (filesAndFolders.hasNext()) {
        Path file = filesAndFolders.next();
        if (directory.equals(file.getParent())) {
            found.add(file);
        }
    }
    return found.toArray(new Path[0]);
}
Also used : Path(java.nio.file.Path) NotDirectoryException(java.nio.file.NotDirectoryException) NoSuchFileException(java.nio.file.NoSuchFileException) HashSet(java.util.HashSet) CombiningIterator(org.neo4j.internal.helpers.collection.CombiningIterator)

Example 2 with CombiningIterator

use of org.neo4j.internal.helpers.collection.CombiningIterator in project neo4j by neo4j.

the class EphemeralFileSystemAbstraction method listFiles.

@Override
public Path[] listFiles(Path directory, DirectoryStream.Filter<Path> filter) {
    directory = canonicalFile(directory);
    if (files.containsKey(directory)) // This means that you're trying to list files on a file, not a directory.
    {
        return null;
    }
    Set<Path> found = new HashSet<>();
    Iterator<Path> files = new CombiningIterator<>(asList(this.files.keySet().iterator(), directories.iterator()));
    while (files.hasNext()) {
        Path path = files.next();
        if (directory.equals(path.getParent())) {
            try {
                if (filter.accept(path)) {
                    found.add(path);
                }
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }
    }
    return found.toArray(new Path[0]);
}
Also used : Path(java.nio.file.Path) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) HashSet(java.util.HashSet) CombiningIterator(org.neo4j.internal.helpers.collection.CombiningIterator)

Aggregations

Path (java.nio.file.Path)2 HashSet (java.util.HashSet)2 CombiningIterator (org.neo4j.internal.helpers.collection.CombiningIterator)2 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 NotDirectoryException (java.nio.file.NotDirectoryException)1