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 File: BundleFileSystemProvider.java From incubator-taverna-language with Apache License 2.0 | 6 votes |
@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 #2
Source File: SFTPFileSystemDirectoryStreamTest.java From sftp-fs with Apache License 2.0 | 6 votes |
@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 #3
Source File: SFTPFileSystem.java From sftp-fs with Apache License 2.0 | 6 votes |
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 #4
Source File: ShuffleFS.java From lucene-solr with Apache License 2.0 | 6 votes |
@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 #5
Source File: MCRFileSystemProvider.java From mycore with GNU General Public License v3.0 | 5 votes |
@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 #6
Source File: DefaultProjectFilesystem.java From buck with Apache License 2.0 | 5 votes |
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 #7
Source File: DefaultProjectFilesystem.java From buck with Apache License 2.0 | 5 votes |
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 #8
Source File: DefaultProjectFilesystem.java From buck with Apache License 2.0 | 5 votes |
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 #9
Source File: UnixSshFileSystemProvider.java From jsch-nio with MIT License | 5 votes |
@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 #10
Source File: FileSystemDeploymentService.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
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 #11
Source File: DataBundles.java From incubator-taverna-language with Apache License 2.0 | 5 votes |
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 #12
Source File: FilterFileSystemProvider.java From lucene-solr with Apache License 2.0 | 5 votes |
@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 #13
Source File: JFileSystemProvider.java From baratine with GNU General Public License v2.0 | 5 votes |
@Override public DirectoryStream<Path> newDirectoryStream(Path dir, Filter<? super Path> filter) throws IOException { JPath jPath = (JPath) dir; return new JDirectoryStream(jPath, filter); }
Example #14
Source File: FileProviderBase.java From baratine with GNU General Public License v2.0 | 5 votes |
@Override public DirectoryStream<Path> newDirectoryStream(Path dir, Filter<? super Path> filter) throws IOException { throw new UnsupportedOperationException(); }
Example #15
Source File: MCRFileSystemProvider.java From mycore with GNU General Public License v3.0 | 5 votes |
@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 #16
Source File: ZipFileSystemProvider.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
@Override public DirectoryStream<Path> newDirectoryStream( Path path, Filter<? super Path> filter) throws IOException { return toZipPath(path).newDirectoryStream(filter); }
Example #17
Source File: AcmeFileSystemProvider.java From quarkus with Apache License 2.0 | 4 votes |
@Override public DirectoryStream<Path> newDirectoryStream(Path dir, Filter<? super Path> filter) throws IOException { return null; }
Example #18
Source File: JrtPath.java From Bytecoder with Apache License 2.0 | 4 votes |
final DirectoryStream<Path> newDirectoryStream(Filter<? super Path> filter) throws IOException { return new JrtDirectoryStream(this, filter); }
Example #19
Source File: SFTPFileSystemProvider.java From sftp-fs with Apache License 2.0 | 4 votes |
@Override public DirectoryStream<Path> newDirectoryStream(Path dir, Filter<? super Path> filter) throws IOException { return toSFTPPath(dir).newDirectoryStream(filter); }
Example #20
Source File: ZipPath.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
DirectoryStream<Path> newDirectoryStream(Filter<? super Path> filter) throws IOException { return new ZipDirectoryStream(this, filter); }
Example #21
Source File: ZipFileSystemProvider.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
@Override public DirectoryStream<Path> newDirectoryStream( Path path, Filter<? super Path> filter) throws IOException { return toZipPath(path).newDirectoryStream(filter); }
Example #22
Source File: ZipPath.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
DirectoryStream<Path> newDirectoryStream(Filter<? super Path> filter) throws IOException { return new ZipDirectoryStream(this, filter); }
Example #23
Source File: ZipFileSystemProvider.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
@Override public DirectoryStream<Path> newDirectoryStream( Path path, Filter<? super Path> filter) throws IOException { return toZipPath(path).newDirectoryStream(filter); }
Example #24
Source File: Bug1399.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
@ExpectWarning("OS_OPEN_STREAM") void test6(File f, byte b) throws IOException { DirectoryStream<Path> c = Files.newDirectoryStream(Paths.get(""), (Filter)null); c.hashCode(); }
Example #25
Source File: ZipPath.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
DirectoryStream<Path> newDirectoryStream(Filter<? super Path> filter) throws IOException { return new ZipDirectoryStream(this, filter); }
Example #26
Source File: SFTPFileSystem.java From sftp-fs with Apache License 2.0 | 4 votes |
private SFTPPathDirectoryStream(SFTPPath path, List<LsEntry> entries, Filter<? super Path> filter) { super(filter); this.path = path; this.entries = entries; }
Example #27
Source File: ZipPath.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
DirectoryStream<Path> newDirectoryStream(Filter<? super Path> filter) throws IOException { return new ZipDirectoryStream(this, filter); }
Example #28
Source File: ZipFileSystemProvider.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
@Override public DirectoryStream<Path> newDirectoryStream( Path path, Filter<? super Path> filter) throws IOException { return toZipPath(path).newDirectoryStream(filter); }
Example #29
Source File: HadoopPath.java From jsr203-hadoop with Apache License 2.0 | 4 votes |
DirectoryStream<Path> newDirectoryStream(Filter<? super Path> filter) throws IOException { return new HadoopDirectoryStream(this, filter); }
Example #30
Source File: HadoopFileSystemProvider.java From jsr203-hadoop with Apache License 2.0 | 4 votes |
@Override public DirectoryStream<Path> newDirectoryStream(Path dir, Filter<? super Path> filter) throws IOException { return toHadoopPath(dir).newDirectoryStream(filter); }