类java.nio.file.DirectoryStream.Filter源码实例Demo

下面列出了怎么用java.nio.file.DirectoryStream.Filter的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: lucene-solr   文件: ShuffleFS.java
@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 {}        
    };
  }
}
 
源代码2 项目: sftp-fs   文件: SFTPFileSystem.java
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);
    }
}
 
@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));
}
 
@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());
		}
	};
}
 
源代码5 项目: mycore   文件: MCRFileSystemProvider.java
@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());
}
 
源代码6 项目: mycore   文件: MCRFileSystemProvider.java
@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());
}
 
源代码7 项目: baratine   文件: FileProviderBase.java
@Override
public DirectoryStream<Path> newDirectoryStream(Path dir,
                                                Filter<? super Path> filter)
                                                    throws IOException
{
  throw new UnsupportedOperationException();
}
 
源代码8 项目: baratine   文件: JFileSystemProvider.java
@Override
public DirectoryStream<Path> newDirectoryStream(Path dir,
                                                Filter<? super Path> filter)
  throws IOException
{
  JPath jPath = (JPath) dir;

  return new JDirectoryStream(jPath, filter);
}
 
源代码9 项目: lucene-solr   文件: FilterFileSystemProvider.java
@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);
}
 
源代码10 项目: incubator-taverna-language   文件: DataBundles.java
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);
	}
}
 
源代码11 项目: wildfly-core   文件: FileSystemDeploymentService.java
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);
    }
}
 
源代码12 项目: jsch-nio   文件: UnixSshFileSystemProvider.java
@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 );
}
 
源代码13 项目: buck   文件: DefaultProjectFilesystem.java
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());
}
 
源代码14 项目: buck   文件: DefaultProjectFilesystem.java
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();
}
 
源代码15 项目: buck   文件: DefaultProjectFilesystem.java
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;
}
 
源代码16 项目: dragonwell8_jdk   文件: ZipPath.java
DirectoryStream<Path> newDirectoryStream(Filter<? super Path> filter)
    throws IOException
{
    return new ZipDirectoryStream(this, filter);
}
 
源代码17 项目: dragonwell8_jdk   文件: ZipFileSystemProvider.java
@Override
public DirectoryStream<Path> newDirectoryStream(
    Path path, Filter<? super Path> filter) throws IOException
{
    return toZipPath(path).newDirectoryStream(filter);
}
 
源代码18 项目: TencentKona-8   文件: ZipPath.java
DirectoryStream<Path> newDirectoryStream(Filter<? super Path> filter)
    throws IOException
{
    return new ZipDirectoryStream(this, filter);
}
 
源代码19 项目: TencentKona-8   文件: ZipFileSystemProvider.java
@Override
public DirectoryStream<Path> newDirectoryStream(
    Path path, Filter<? super Path> filter) throws IOException
{
    return toZipPath(path).newDirectoryStream(filter);
}
 
源代码20 项目: jdk8u60   文件: ZipPath.java
DirectoryStream<Path> newDirectoryStream(Filter<? super Path> filter)
    throws IOException
{
    return new ZipDirectoryStream(this, filter);
}
 
源代码21 项目: jdk8u60   文件: ZipFileSystemProvider.java
@Override
public DirectoryStream<Path> newDirectoryStream(
    Path path, Filter<? super Path> filter) throws IOException
{
    return toZipPath(path).newDirectoryStream(filter);
}
 
源代码22 项目: quarkus   文件: AcmeFileSystemProvider.java
@Override
public DirectoryStream<Path> newDirectoryStream(Path dir, Filter<? super Path> filter) throws IOException {
	return null;
}
 
源代码23 项目: openjdk-jdk8u   文件: ZipPath.java
DirectoryStream<Path> newDirectoryStream(Filter<? super Path> filter)
    throws IOException
{
    return new ZipDirectoryStream(this, filter);
}
 
源代码24 项目: openjdk-jdk8u   文件: ZipFileSystemProvider.java
@Override
public DirectoryStream<Path> newDirectoryStream(
    Path path, Filter<? super Path> filter) throws IOException
{
    return toZipPath(path).newDirectoryStream(filter);
}
 
@Override
public DirectoryStream<Path> newDirectoryStream(Path dir,
		Filter<? super Path> filter) throws IOException {
	return null;
}
 
源代码26 项目: openjdk-jdk8u-backup   文件: ZipPath.java
DirectoryStream<Path> newDirectoryStream(Filter<? super Path> filter)
    throws IOException
{
    return new ZipDirectoryStream(this, filter);
}
 
@Override
public DirectoryStream<Path> newDirectoryStream(
    Path path, Filter<? super Path> filter) throws IOException
{
    return toZipPath(path).newDirectoryStream(filter);
}
 
源代码28 项目: Bytecoder   文件: JrtPath.java
final DirectoryStream<Path> newDirectoryStream(Filter<? super Path> filter)
        throws IOException {
    return new JrtDirectoryStream(this, filter);
}
 
源代码29 项目: Bytecoder   文件: JrtFileSystemProvider.java
@Override
public DirectoryStream<Path> newDirectoryStream(
        Path path, Filter<? super Path> filter) throws IOException {
    return toJrtPath(path).newDirectoryStream(filter);
}
 
源代码30 项目: openjdk-jdk9   文件: JrtPath.java
final DirectoryStream<Path> newDirectoryStream(Filter<? super Path> filter)
        throws IOException {
    return new JrtDirectoryStream(this, filter);
}
 
 类所在包
 类方法
 同包方法