java.nio.file.DirectoryStream.Filter Java Examples

The following examples show how to use java.nio.file.DirectoryStream.Filter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: lucene-solr   Author: apache   File: ShuffleFS.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public DirectoryStream<Path> newDirectoryStream(Path dir, Filter<? super Path> filter) throws IOException {
  try (DirectoryStream<Path> stream = super.newDirectoryStream(dir, filter)) {
    // read complete directory listing
    List<Path> contents = new ArrayList<>();
    for (Path path : stream) {
      contents.add(path);
    }
    // sort first based only on filename
    Collections.sort(contents, (path1, path2) -> path1.getFileName().toString().compareTo(path2.getFileName().toString()));
    // sort based on current class seed
    Collections.shuffle(contents, new Random(seed));
    return new DirectoryStream<Path>() {
      @Override
      public Iterator<Path> iterator() {
        return contents.iterator();
      }
      @Override
      public void close() throws IOException {}        
    };
  }
}
 
Example #2
Source Project: sftp-fs   Author: robtimus   File: SFTPFileSystem.java    License: Apache License 2.0 6 votes vote down vote up
DirectoryStream<Path> newDirectoryStream(final SFTPPath path, Filter<? super Path> filter) throws IOException {
    try (Channel channel = channelPool.get()) {
        List<LsEntry> entries = channel.listFiles(path.path());
        boolean isDirectory = false;
        for (Iterator<LsEntry> i = entries.iterator(); i.hasNext(); ) {
            LsEntry entry = i.next();
            String filename = entry.getFilename();
            if (CURRENT_DIR.equals(filename)) {
                isDirectory = true;
                i.remove();
            } else if (PARENT_DIR.equals(filename)) {
                i.remove();
            }
        }

        if (!isDirectory) {
            // https://github.com/robtimus/sftp-fs/issues/4: don't fail immediately but check the attributes
            // Follow links to ensure the directory attribute can be read correctly
            SftpATTRS attributes = channel.readAttributes(path.path(), true);
            if (!attributes.isDir()) {
                throw new NotDirectoryException(path.path());
            }
        }
        return new SFTPPathDirectoryStream(path, entries, filter);
    }
}
 
Example #3
Source Project: sftp-fs   Author: robtimus   File: SFTPFileSystemDirectoryStreamTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFilteredIterator() throws IOException {
    final int count = 100;

    List<Matcher<? super String>> matchers = new ArrayList<>();
    for (int i = 0; i < count; i++) {
        if (i % 2 == 1) {
            matchers.add(equalTo("file" + i));
        }
        addFile("/foo/file" + i);
    }

    List<String> names = new ArrayList<>();
    Filter<Path> filter = new PatternFilter("file\\d*[13579]");
    try (DirectoryStream<Path> stream = fileSystem.newDirectoryStream(createPath("/foo"), filter)) {
        for (Iterator<Path> iterator = stream.iterator(); iterator.hasNext(); ) {
            names.add(iterator.next().getFileName().toString());
        }
    }
    assertThat(names, containsInAnyOrder(matchers));
}
 
Example #4
Source Project: incubator-taverna-language   Author: apache   File: BundleFileSystemProvider.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public DirectoryStream<Path> newDirectoryStream(Path dir,
		final Filter<? super Path> filter) throws IOException {
	final BundleFileSystem fs = (BundleFileSystem) dir.getFileSystem();
	final DirectoryStream<Path> stream = origProvider(dir)
			.newDirectoryStream(fs.unwrap(dir), new Filter<Path>() {
				@Override
				public boolean accept(Path entry) throws IOException {
					return filter.accept(fs.wrap(entry));
				}
			});
	return new DirectoryStream<Path>() {
		@Override
		public void close() throws IOException {
			stream.close();
		}

		@Override
		public Iterator<Path> iterator() {
			return fs.wrapIterator(stream.iterator());
		}
	};
}
 
Example #5
Source Project: mycore   Author: MyCoRe-Org   File: MCRFileSystemProvider.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public DirectoryStream<Path> newDirectoryStream(Path dir, Filter<? super Path> filter) throws IOException {
    MCRPath mcrPath = MCRFileSystemUtils.checkPathAbsolute(dir);
    MCRStoredNode node = MCRFileSystemUtils.resolvePath(mcrPath);
    if (node instanceof MCRDirectory) {
        return MCRDirectoryStream.getInstance((MCRDirectory) node, mcrPath);
    }
    throw new NotDirectoryException(dir.toString());
}
 
Example #6
Source Project: mycore   Author: MyCoRe-Org   File: MCRFileSystemProvider.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public DirectoryStream<Path> newDirectoryStream(Path dir, Filter<? super Path> filter) throws IOException {
    MCRPath mcrPath = MCRFileSystemUtils.checkPathAbsolute(dir);
    MCRFilesystemNode node = resolvePath(mcrPath);
    if (node instanceof MCRDirectory) {
        return new MCRDirectoryStream((MCRDirectory) node, mcrPath);
    }
    throw new NotDirectoryException(dir.toString());
}
 
Example #7
Source Project: baratine   Author: baratine   File: FileProviderBase.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public DirectoryStream<Path> newDirectoryStream(Path dir,
                                                Filter<? super Path> filter)
                                                    throws IOException
{
  throw new UnsupportedOperationException();
}
 
Example #8
Source Project: baratine   Author: baratine   File: JFileSystemProvider.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public DirectoryStream<Path> newDirectoryStream(Path dir,
                                                Filter<? super Path> filter)
  throws IOException
{
  JPath jPath = (JPath) dir;

  return new JDirectoryStream(jPath, filter);
}
 
Example #9
Source Project: lucene-solr   Author: apache   File: FilterFileSystemProvider.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public DirectoryStream<Path> newDirectoryStream(Path dir, final Filter<? super Path> filter) throws IOException {
  Filter<Path> wrappedFilter = new Filter<Path>() {
    @Override
    public boolean accept(Path entry) throws IOException {
      return filter.accept(new FilterPath(entry, fileSystem));
    }
  };
  return new FilterDirectoryStream(delegate.newDirectoryStream(toDelegate(dir), wrappedFilter), fileSystem);
}
 
Example #10
Source Project: incubator-taverna-language   Author: apache   File: DataBundles.java    License: Apache License 2.0 5 votes vote down vote up
public static void deleteAllExtensions(final Path file) throws IOException {
	Filter<Path> filter = new ExtensionIgnoringFilter(file);
	try (DirectoryStream<Path> ds = newDirectoryStream(file.getParent(),
			filter)) {
		for (Path p : ds)
			deleteRecursively(p);
	}
}
 
Example #11
Source Project: wildfly-core   Author: wildfly   File: FileSystemDeploymentService.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
private static List<File> listDirectoryChildren(File directory, DirectoryStream.Filter<Path> filter) {
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(directory.toPath(), filter)) {
        final List<File> result = new ArrayList<>();
        for (Path entry : stream) {
            result.add(entry.toFile());
        }
        return result;
    } catch (SecurityException | IOException ex) {
        throw DeploymentScannerLogger.ROOT_LOGGER.cannotListDirectoryFiles(ex, directory);
    }
}
 
Example #12
Source Project: jsch-nio   Author: lucastheisen   File: UnixSshFileSystemProvider.java    License: MIT License 5 votes vote down vote up
@Override
public DirectoryStream<Path> newDirectoryStream( Path path, Filter<? super Path> filter ) throws IOException {
    UnixSshPath unixPath = checkPath( path );
    String result = executeForStdout( unixPath, unixPath.getFileSystem().getCommand( "ls" )
            + " -A -1 " + unixPath.toAbsolutePath().quotedString() );
    String[] items = result.split( "\n" );
    if ( items.length == 1 && items[0].isEmpty() ) {
        items = null;
    }
    return new StandardDirectoryStream( path, items, filter );
}
 
Example #13
Source Project: buck   Author: facebook   File: DefaultProjectFilesystem.java    License: Apache License 2.0 5 votes vote down vote up
void walkRelativeFileTree(
    Path pathRelativeToProjectRoot,
    EnumSet<FileVisitOption> visitOptions,
    FileVisitor<Path> fileVisitor,
    DirectoryStream.Filter<? super Path> ignoreFilter)
    throws IOException {
  Path rootPath = getPathForRelativePath(pathRelativeToProjectRoot);
  walkFileTreeWithPathMapping(
      rootPath, visitOptions, fileVisitor, ignoreFilter, path -> relativize(path).getPath());
}
 
Example #14
Source Project: buck   Author: facebook   File: DefaultProjectFilesystem.java    License: Apache License 2.0 5 votes vote down vote up
void walkFileTree(
    Path root,
    Set<FileVisitOption> options,
    FileVisitor<Path> fileVisitor,
    DirectoryStream.Filter<? super Path> ignoreFilter)
    throws IOException {
  root = getPathForRelativePath(root);
  new FileTreeWalker(root, options, fileVisitor, ignoreFilter).walk();
}
 
Example #15
Source Project: buck   Author: facebook   File: DefaultProjectFilesystem.java    License: Apache License 2.0 5 votes vote down vote up
FileTreeWalker(
    Path root,
    Set<FileVisitOption> options,
    FileVisitor<Path> pathFileVisitor,
    DirectoryStream.Filter<? super Path> ignoreFilter) {
  this.followLinks = options.contains(FileVisitOption.FOLLOW_LINKS);
  this.visitor = pathFileVisitor;
  this.root = root;
  this.state = new ArrayDeque<>();
  this.ignoreFilter = ignoreFilter;
}
 
Example #16
Source Project: dragonwell8_jdk   Author: alibaba   File: ZipPath.java    License: GNU General Public License v2.0 4 votes vote down vote up
DirectoryStream<Path> newDirectoryStream(Filter<? super Path> filter)
    throws IOException
{
    return new ZipDirectoryStream(this, filter);
}
 
Example #17
Source Project: dragonwell8_jdk   Author: alibaba   File: ZipFileSystemProvider.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public DirectoryStream<Path> newDirectoryStream(
    Path path, Filter<? super Path> filter) throws IOException
{
    return toZipPath(path).newDirectoryStream(filter);
}
 
Example #18
Source Project: TencentKona-8   Author: Tencent   File: ZipPath.java    License: GNU General Public License v2.0 4 votes vote down vote up
DirectoryStream<Path> newDirectoryStream(Filter<? super Path> filter)
    throws IOException
{
    return new ZipDirectoryStream(this, filter);
}
 
Example #19
Source Project: TencentKona-8   Author: Tencent   File: ZipFileSystemProvider.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public DirectoryStream<Path> newDirectoryStream(
    Path path, Filter<? super Path> filter) throws IOException
{
    return toZipPath(path).newDirectoryStream(filter);
}
 
Example #20
Source Project: jdk8u60   Author: chenghanpeng   File: ZipPath.java    License: GNU General Public License v2.0 4 votes vote down vote up
DirectoryStream<Path> newDirectoryStream(Filter<? super Path> filter)
    throws IOException
{
    return new ZipDirectoryStream(this, filter);
}
 
Example #21
Source Project: jdk8u60   Author: chenghanpeng   File: ZipFileSystemProvider.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public DirectoryStream<Path> newDirectoryStream(
    Path path, Filter<? super Path> filter) throws IOException
{
    return toZipPath(path).newDirectoryStream(filter);
}
 
Example #22
Source Project: quarkus   Author: quarkusio   File: AcmeFileSystemProvider.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public DirectoryStream<Path> newDirectoryStream(Path dir, Filter<? super Path> filter) throws IOException {
	return null;
}
 
Example #23
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: ZipPath.java    License: GNU General Public License v2.0 4 votes vote down vote up
DirectoryStream<Path> newDirectoryStream(Filter<? super Path> filter)
    throws IOException
{
    return new ZipDirectoryStream(this, filter);
}
 
Example #24
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: ZipFileSystemProvider.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public DirectoryStream<Path> newDirectoryStream(
    Path path, Filter<? super Path> filter) throws IOException
{
    return toZipPath(path).newDirectoryStream(filter);
}
 
Example #25
Source Project: openjdk-systemtest   Author: AdoptOpenJDK   File: AMemoryFileSystemProvider.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public DirectoryStream<Path> newDirectoryStream(Path dir,
		Filter<? super Path> filter) throws IOException {
	return null;
}
 
Example #26
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: ZipPath.java    License: GNU General Public License v2.0 4 votes vote down vote up
DirectoryStream<Path> newDirectoryStream(Filter<? super Path> filter)
    throws IOException
{
    return new ZipDirectoryStream(this, filter);
}
 
Example #27
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: ZipFileSystemProvider.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public DirectoryStream<Path> newDirectoryStream(
    Path path, Filter<? super Path> filter) throws IOException
{
    return toZipPath(path).newDirectoryStream(filter);
}
 
Example #28
Source Project: Bytecoder   Author: mirkosertic   File: JrtPath.java    License: Apache License 2.0 4 votes vote down vote up
final DirectoryStream<Path> newDirectoryStream(Filter<? super Path> filter)
        throws IOException {
    return new JrtDirectoryStream(this, filter);
}
 
Example #29
Source Project: Bytecoder   Author: mirkosertic   File: JrtFileSystemProvider.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public DirectoryStream<Path> newDirectoryStream(
        Path path, Filter<? super Path> filter) throws IOException {
    return toJrtPath(path).newDirectoryStream(filter);
}
 
Example #30
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: JrtPath.java    License: GNU General Public License v2.0 4 votes vote down vote up
final DirectoryStream<Path> newDirectoryStream(Filter<? super Path> filter)
        throws IOException {
    return new JrtDirectoryStream(this, filter);
}