java.nio.file.DirectoryStream#Filter ( )源码实例Demo

下面列出了java.nio.file.DirectoryStream#Filter ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

private DirectoryStream<Path> newDirectoryStream(Path attachmentPath, Site.Attachment attachment)
        throws IOException {

    if (StringUtils.isNotBlank(attachment.getName())) {
        return Files.newDirectoryStream(attachmentPath, attachment.getName());
    }

    final DirectoryStream.Filter<Path> filter = new DirectoryStream.Filter<Path>() {
        @Override
        public boolean accept(Path entry) throws IOException {

            return !(Files.isDirectory(entry) || Files.isHidden(entry) || Files.isSymbolicLink(entry)
                    || (!Files.isReadable(entry)));
        }
    };
    return Files.newDirectoryStream(attachmentPath, filter);
}
 
源代码2 项目: openjdk-jdk9   文件: JrtDirectoryStream.java
JrtDirectoryStream(JrtPath dir,
        DirectoryStream.Filter<? super java.nio.file.Path> filter)
        throws IOException
{
    this.dir = dir;
    if (!dir.jrtfs.isDirectory(dir, true)) {  // sanity check
        throw new NotDirectoryException(dir.toString());
    }
    this.filter = filter;
}
 
源代码3 项目: jimfs   文件: FileSystemView.java
/**
 * Creates a new directory stream for the directory located by the given path. The given {@code
 * basePathForStream} is that base path that the returned stream will use. This will be the same
 * as {@code dir} except for streams created relative to another secure stream.
 */
public DirectoryStream<Path> newDirectoryStream(
    JimfsPath dir,
    DirectoryStream.Filter<? super Path> filter,
    Set<? super LinkOption> options,
    JimfsPath basePathForStream)
    throws IOException {
  Directory file = (Directory) lookUpWithLock(dir, options).requireDirectory(dir).file();
  FileSystemView view = new FileSystemView(store, file, basePathForStream);
  JimfsSecureDirectoryStream stream = new JimfsSecureDirectoryStream(view, filter, state());
  return store.supportsFeature(Feature.SECURE_DIRECTORY_STREAM)
      ? stream
      : new DowngradedDirectoryStream(stream);
}
 
源代码4 项目: lucene-solr   文件: SolrResourceLoader.java
/**
 * Utility method to get the URLs of all paths under a given directory that match a filter
 *
 * @param libDir the root directory
 * @param filter the filter
 * @return all matching URLs
 * @throws IOException on error
 */
public static List<URL> getURLs(Path libDir, DirectoryStream.Filter<Path> filter) throws IOException {
  List<URL> urls = new ArrayList<>();
  try (DirectoryStream<Path> directory = Files.newDirectoryStream(libDir, filter)) {
    for (Path element : directory) {
      urls.add(element.toUri().normalize().toURL());
    }
  }
  return urls;
}
 
源代码5 项目: TencentKona-8   文件: ZipDirectoryStream.java
ZipDirectoryStream(ZipPath zipPath,
                   DirectoryStream.Filter<? super java.nio.file.Path> filter)
    throws IOException
{
    this.zipfs = zipPath.getFileSystem();
    this.path = zipPath.getResolvedPath();
    this.filter = filter;
    // sanity check
    if (!zipfs.isDirectory(path))
        throw new NotDirectoryException(zipPath.toString());
}
 
源代码6 项目: TencentKona-8   文件: FaultyFileSystem.java
@Override
public DirectoryStream<Path> newDirectoryStream(Path dir, DirectoryStream.Filter<? super Path> filter)
    throws IOException
{
    triggerEx(dir, "newDirectoryStream");
    return wrap(Files.newDirectoryStream(unwrap(dir), filter));
}
 
源代码7 项目: 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());
}
 
@Override
public boolean isFileRolled(LiveFile currentFile) throws IOException {
  DirectoryStream.Filter<Path> filter = new FileFilter(currentFile.getPath());
  try (DirectoryStream<Path> matches = Files.newDirectoryStream(currentFile.getPath().getParent(), filter)) {
    return matches.iterator().hasNext();
  }
}
 
@Override
protected void run0() throws Exception {
    logger.info(request.toString());

    final FileLock fileLock = new GlobalLock(request.lockFile).waitForLock();

    try {
        // generate manifest (set of object keys and source files defining the upload)
        final Collection<ManifestEntry> manifest = new LinkedList<>(); // linked list to maintain order
        final Pattern pattern = Pattern.compile("CommitLog-\\d+-\\d+\\.log");
        final DirectoryStream.Filter<Path> filter = entry -> Files.isRegularFile(entry) && pattern.matcher(entry.getFileName().toString()).matches();

        final Path commitLogArchiveDirectory = resolveCommitLogsPath(request);
        final Path backupCommitLogRootKey = Paths.get(CASSANDRA_COMMIT_LOGS);

        try (final DirectoryStream<Path> commitLogs = Files.newDirectoryStream(commitLogArchiveDirectory, filter);
            final Backuper backuper = backuperFactoryMap.get(request.storageLocation.storageProvider).createCommitLogBackuper(request);
            final BucketService bucketService = bucketServiceMap.get(request.storageLocation.storageProvider).createBucketService(request)) {

            bucketService.createIfMissing(request.storageLocation.bucket);

            for (final Path commitLog : commitLogs) {
                // Append file modified date so we have some idea of the time range this commitlog covers

                // millisecond precision, on *nix, it trims milliseconds and returns "000" instead
                // when using File.lastModified
                long commitLogLastModified = Files.getLastModifiedTime(commitLog.toFile().toPath()).toMillis();

                final Path bucketKey = backupCommitLogRootKey.resolve(commitLog.getFileName().toString() + "." + commitLogLastModified);
                manifest.add(new ManifestEntry(bucketKey, commitLog, ManifestEntry.Type.FILE));
            }

            logger.debug("{} files in manifest for commitlog backup.", manifest.size());

            backuper.uploadOrFreshenFiles(this, manifest, new OperationProgressTracker(this, manifest.size()));
        }
    } finally {
        fileLock.release();
    }
}
 
源代码10 项目: tessera   文件: DelegatingFileSystemProviderTest.java
@Test
public void newDirectoryStream() throws IOException {
    final Path path = mock(Path.class);
    final DirectoryStream.Filter<Path> filter = mock(DirectoryStream.Filter.class);

    provider.newDirectoryStream(path, filter);

    verify(delegate).newDirectoryStream(path, filter);
}
 
源代码11 项目: 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;
}
 
protected final AnalysedDirectory getImportableDirectoriesInDirectory(ImportableItem directory, final int count)
{
    DirectoryStream.Filter<Path> filter = null;

	if (count != -1)
	{
        filter = new DirectoryStream.Filter<Path>()
        {
            private int i = count;

            @Override
            public boolean accept(Path entry) throws IOException
            {
                return Files.isDirectory(entry) && i-- > 0;
            }
        };
	}
	else
	{
        filter = new DirectoryStream.Filter<Path>()
        {
            @Override
            public boolean accept(Path entry) throws IOException
            {
                return Files.isDirectory(entry);
            }
        };
	}

    AnalysedDirectory analysedDirectory = directoryAnalyser.analyseDirectory(directory, filter);
    return analysedDirectory;
}
 
源代码13 项目: js-dossier   文件: Paths.java
/**
 * Expands the given directory path, collecting all of its descendant files that are accepted by
 * the filter.
 *
 * @param dir The directory to expand.
 * @param filter The filter to apply to the directory entries.
 * @return All of the files located under the directory accepted by the filter.
 * @throws IOException If an I/O error occurs.
 */
static List<Path> expandDir(Path dir, DirectoryStream.Filter<Path> filter) throws IOException {
  checkArgument(Files.isDirectory(dir), "%s is not a directory", dir);
  List<Path> paths = new LinkedList<>();
  try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, filter)) {
    for (Path path : stream) {
      if (Files.isDirectory(path)) {
        paths.addAll(expandDir(path, filter));
      } else {
        paths.add(path);
      }
    }
  }
  return paths;
}
 
源代码14 项目: mycore   文件: MCRDirectoryStream.java
static DirectoryStream<Path> getInstance(MCRDirectory dir, MCRPath path) throws IOException {
    DirectoryStream.Filter<Path> filter = (dir instanceof MCRFileCollection) ? MCRFileCollectionFilter.FILTER
        : AcceptAllFilter.FILTER;
    LOGGER.debug("Dir {}, class {}, filter {}", path, dir.getClass(), filter.getClass());
    DirectoryStream<Path> baseDirectoryStream = Files.newDirectoryStream(dir.getLocalPath(), filter);
    LOGGER.debug("baseStream {}", baseDirectoryStream.getClass());
    if (baseDirectoryStream instanceof java.nio.file.SecureDirectoryStream) {
        LOGGER.debug("Returning SecureDirectoryStream");
        return new SecureDirectoryStream(dir, path,
            (java.nio.file.SecureDirectoryStream<Path>) baseDirectoryStream);
    }
    return new SimpleDirectoryStream(path, baseDirectoryStream);
}
 
源代码15 项目: jdk8u-jdk   文件: ZipDirectoryStream.java
ZipDirectoryStream(ZipPath zipPath,
                   DirectoryStream.Filter<? super java.nio.file.Path> filter)
    throws IOException
{
    this.zipfs = zipPath.getFileSystem();
    this.path = zipPath.getResolvedPath();
    this.filter = filter;
    // sanity check
    if (!zipfs.isDirectory(path))
        throw new NotDirectoryException(zipPath.toString());
}
 
源代码16 项目: jdk8u-jdk   文件: FaultyFileSystem.java
@Override
public DirectoryStream<Path> newDirectoryStream(Path dir, DirectoryStream.Filter<? super Path> filter)
    throws IOException
{
    triggerEx(dir, "newDirectoryStream");
    return wrap(Files.newDirectoryStream(unwrap(dir), filter));
}
 
源代码17 项目: jimfs   文件: SystemJimfsFileSystemProvider.java
@Override
public DirectoryStream<Path> newDirectoryStream(
    Path dir, DirectoryStream.Filter<? super Path> filter) throws IOException {
  throw new UnsupportedOperationException();
}
 
源代码18 项目: encfs4j   文件: EncryptedFileSystemProvider.java
@Override
public DirectoryStream<Path> newDirectoryStream(Path dir,
		DirectoryStream.Filter<? super Path> filter) throws IOException {
	return mantle(Files.newDirectoryStream(
			EncryptedFileSystem.dismantle(dir), filter));
}
 
源代码19 项目: crate   文件: FileSystemUtils.java
/**
 * Returns an array of all files in the given directory matching.
 */
public static Path[] files(Path from, DirectoryStream.Filter<Path> filter) throws IOException {
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(from, filter)) {
        return toArray(stream);
    }
}
 
源代码20 项目: Bytecoder   文件: FileSystemProvider.java
/**
 * Opens a directory, returning a {@code DirectoryStream} to iterate over
 * the entries in the directory. This method works in exactly the manner
 * specified by the {@link
 * Files#newDirectoryStream(java.nio.file.Path, java.nio.file.DirectoryStream.Filter)}
 * method.
 *
 * @param   dir
 *          the path to the directory
 * @param   filter
 *          the directory stream filter
 *
 * @return  a new and open {@code DirectoryStream} object
 *
 * @throws  NotDirectoryException
 *          if the file could not otherwise be opened because it is not
 *          a directory <i>(optional specific exception)</i>
 * @throws  IOException
 *          if an I/O error occurs
 * @throws  SecurityException
 *          In the case of the default provider, and a security manager is
 *          installed, the {@link SecurityManager#checkRead(String) checkRead}
 *          method is invoked to check read access to the directory.
 */
public abstract DirectoryStream<Path> newDirectoryStream(Path dir,
     DirectoryStream.Filter<? super Path> filter) throws IOException;