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

项目:java-cloud-filesystem-provider    文件:PathFiltersTest.java   
@Test
public void testAndFilterLogicallyAndsAllFiltersAndDoesNotAcceptIfOneOfTheFiltersIsFalse() throws IOException {
    Filter<Path> filter1 = context.mock(Filter.class, "filter1");
    Filter<Path> filter2 = context.mock(Filter.class, "filter2");
    Filter<Path> filter3 = context.mock(Filter.class, "filter3");
    Path mockPath = context.mock(Path.class);

    context.checking(new Expectations() {{
        atMost(1).of(filter1).accept(with(any(Path.class))); will(returnValue(true));
        atMost(1).of(filter2).accept(with(any(Path.class))); will(returnValue(true));
        atMost(1).of(filter3).accept(with(any(Path.class))); will(returnValue(false));
    }});

    AggregateAndFilter andFilter = new AggregateAndFilter(Sets.newHashSet(filter1, filter2, filter3));
    Assert.assertFalse(andFilter.accept(mockPath));
}
项目:java-cloud-filesystem-provider    文件:PathFiltersTest.java   
@Test
public void testAndFilterLogicallyAndsAllFiltersAndAcceptsIfAllOfTheFiltersAreTrue() throws IOException {
    Filter<Path> filter1 = context.mock(Filter.class, "filter1");
    Filter<Path> filter2 = context.mock(Filter.class, "filter2");
    Filter<Path> filter3 = context.mock(Filter.class, "filter3");
    Path mockPath = context.mock(Path.class);

    context.checking(new Expectations() {{
        atMost(1).of(filter1).accept(with(any(Path.class))); will(returnValue(true));
        atMost(1).of(filter2).accept(with(any(Path.class))); will(returnValue(true));
        atMost(1).of(filter3).accept(with(any(Path.class))); will(returnValue(true));
    }});

    AggregateAndFilter andFilter = new AggregateAndFilter(Sets.newHashSet(filter1, filter2, filter3));
    Assert.assertTrue(andFilter.accept(mockPath));
}
项目:java-cloud-filesystem-provider    文件:PathFiltersTest.java   
@Test
public void testOrFilterLogicallyOrsAllFiltersAndDoesNotAcceptIfAllOfTheFiltersAreFalse() throws IOException {
    Filter<Path> filter1 = context.mock(Filter.class, "filter1");
    Filter<Path> filter2 = context.mock(Filter.class, "filter2");
    Filter<Path> filter3 = context.mock(Filter.class, "filter3");
    Path mockPath = context.mock(Path.class);

    context.checking(new Expectations() {{
        atMost(1).of(filter1).accept(with(any(Path.class))); will(returnValue(false));
        atMost(1).of(filter2).accept(with(any(Path.class))); will(returnValue(false));
        atMost(1).of(filter3).accept(with(any(Path.class))); will(returnValue(false));
    }});

    AggregateOrFilter orFilter = new AggregateOrFilter(Sets.newHashSet(filter1, filter2, filter3));
    Assert.assertFalse(orFilter.accept(mockPath));
}
项目:java-cloud-filesystem-provider    文件:PathFiltersTest.java   
@Test
public void testOrFilterLogicallyOrsAllFiltersAndAcceptsIfAnyOfTheFiltersAreTrue() throws IOException {
    Filter<Path> filter1 = context.mock(Filter.class, "filter1");
    Filter<Path> filter2 = context.mock(Filter.class, "filter2");
    Filter<Path> filter3 = context.mock(Filter.class, "filter3");
    Path mockPath = context.mock(Path.class);

    context.checking(new Expectations() {{
        atMost(1).of(filter1).accept(with(any(Path.class))); will(returnValue(false));
        atMost(1).of(filter2).accept(with(any(Path.class))); will(returnValue(false));
        atMost(1).of(filter3).accept(with(any(Path.class))); will(returnValue(true));
    }});

    AggregateOrFilter orFilter = new AggregateOrFilter(Sets.newHashSet(filter1, filter2, filter3));
    Assert.assertTrue(orFilter.accept(mockPath));
}
项目:incubator-taverna-language    文件:BundleFileSystemProvider.java   
@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());
        }
    };
}
项目:java-cloud-filesystem-provider    文件:AbstractCliCommand.java   
/**
 * Constructs a filter according to the {@link PathMatcher} rules implemented by
 * {@link DefaultPathMatcher}.
 * 
 * @param   pathFilterString
 * @return  A filter for the pattern
 * @see     FileSystem#getPathMatcher(String)
 * @throws  IllegalArgumentException
 *              If the syntax and pattern cannot be parsed
 */
public Filter<Path> parsePathFilter(String syntaxAndPattern, String fileSystemPathSeparator) throws IllegalArgumentException {
    final DefaultPathMatcher matcher = new DefaultPathMatcher(syntaxAndPattern, fileSystemPathSeparator);

    return new Filter<Path>() {

        @Override
        public boolean accept(Path path) throws IOException {
            return matcher.matches(path);
        }

    };
}
项目:java-cloud-filesystem-provider    文件:AbstractCliCommand.java   
/**
 * Creates an {@link AggregateOrFilter} from all of the filters, so that if any of them match
 * then the path is accepted. Filters are created using {@link #parsePathFilter(String)}.
 * 
 * @param commandOptions
 * @return null if there are no filters created or the {@link AggregateOrFilter}
 * 
 * @see #parsePathFilter(String)
 */
public Filter<Path> createPathFilters(List<UserCommandOption> commandOptions, String fileSystemPathSeparator) {
    if (commandOptions == null || commandOptions.isEmpty()) {
        return null;
    }

    AggregateOrFilter orFilter = new AggregateOrFilter();

    for (UserCommandOption opt : commandOptions) {
        Filter<Path> filter = parsePathFilter(opt.getValue(), fileSystemPathSeparator);
        orFilter.addAggregateFilter(filter);
    }

    return orFilter;
}
项目:java-cloud-filesystem-provider    文件:ListCommand.java   
protected int listDirectoryContents(FileSystemProvider provider, FileSystem fileSystem,
        Filter<Path> pathFilters, Path path, boolean recursive) {
    AtomicInteger pathsCounter = new AtomicInteger(0);

    FileSystemProviderHelper.iterateOverDirectoryContents(fileSystem, Optional.ofNullable(path),
            PathFilters.ACCEPT_ALL_FILTER, recursive,
                subPath -> {
                    pathsCounter.addAndGet(printCloudPathAttributes(fileSystem, pathFilters, subPath.getResultPath()));
                    return true;
                });

    return pathsCounter.get();
}
项目:java-cloud-filesystem-provider    文件:DefaultCloudFileSystemImplementation.java   
/**
 * Directory access is checked using {@link #checkAccess(BlobStoreContext, CloudPath, Set)}
 * with {@link AclEntryPermission#LIST_DIRECTORY}.
 */
@Override
public CloudDirectoryStream newDirectoryStream(BlobStoreContext context, CloudPath dir,
        Filter<CloudPath> filter, boolean isRecursive) throws IOException {
    checkAccess(context, dir, NEW_DIRECTORY_STREAM_PERMS);
    CloudPath dirPath = dir;
    boolean isContainer = dirPath.getRoot() == null;

    // Search in a container if root is null, otherwise check to find a directory
    if (!isContainer) {

        // Attempt to read attributes
        try {
            CloudBasicFileAttributes attributes = readAttributes(context, CloudBasicFileAttributes.class, dir);

            // Look at the parent if this is a file
            if (!attributes.isDirectory()) {
                dirPath = dir.getParent();
            }
        } catch (FileNotFoundException e) {
            LOG.warn("Cloud file path '{}' does not exist, will assume that this is a directory", dir);
        }

    }

    return new CloudDirectoryStream(dirPath, isContainer, isRecursive, filter);
}
项目:java-cloud-filesystem-provider    文件:PathFilters.java   
boolean checkAccepts(Filter<Path> filter, Path entry) {
    try {
        return filter.accept(entry);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
项目: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());
}
项目:baratine    文件:FileProviderBase.java   
@Override
public DirectoryStream<Path> newDirectoryStream(Path dir,
                                                Filter<? super Path> filter)
                                                    throws IOException
{
  throw new UnsupportedOperationException();
}
项目: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);
}
项目:stampo    文件:RootResource.java   
private <T extends Resource> Map<String, T> fromDirectoryStream(Filter<Path> filter, Function<Path, T> mapper, Comparator<T> comparator) {

  //linkedhashmap as we want to preserve the insertion order
  try (DirectoryStream<Path> dirs = Files.newDirectoryStream(path, filter)) {
    return StreamSupport.stream(dirs.spliterator(), false)
          .map(mapper)
          .sorted(comparator)
          .collect(Collectors.toMap(Resource::getName, Function.identity(), (k, v) -> {throw new IllegalStateException("duplicate key " + k);}, LinkedHashMap::new));
  } catch (IOException e) {
    throw new IllegalStateException(e);
  }
}
项目:sonic-scream    文件:FilesEx.java   
public static List<Path> listFiles(Path path, Filter<? super Path> filter) throws IOException
{
    List<Path> files = new ArrayList<>();
    try(DirectoryStream<Path> ds = Files.newDirectoryStream(path, filter))
    {
        for(Path p : ds)
        {
            files.add(p);
        }
    }
    return files;
}
项目:sonic-scream    文件:FilesEx.java   
public static List<Path> getDirectories(Path path) throws IOException
{
    List<Path> dirs = new ArrayList<>();
    DirectoryStream.Filter<Path> filter = (Path file) 
            -> (Files.isDirectory(file));

    try(DirectoryStream<Path> ds = Files.newDirectoryStream(path, filter))
    {
        for(Path p: ds)
        {
            dirs.add(p);
        }
    }
    return dirs;
}
项目: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);
    }
}
项目:zeppelin    文件:InterpreterSettingManager.java   
private void init() throws IOException {

    // 1. detect interpreter setting via interpreter-setting.json in each interpreter folder
    // 2. detect interpreter setting in interpreter.json that is saved before
    String interpreterJson = conf.getInterpreterJson();
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    if (Files.exists(interpreterDirPath)) {
      for (Path interpreterDir : Files
          .newDirectoryStream(interpreterDirPath, new Filter<Path>() {
            @Override
            public boolean accept(Path entry) throws IOException {
              return Files.exists(entry) && Files.isDirectory(entry);
            }
          })) {
        String interpreterDirString = interpreterDir.toString();

        /**
         * Register interpreter by the following ordering
         * 1. Register it from path {ZEPPELIN_HOME}/interpreter/{interpreter_name}/
         *    interpreter-setting.json
         * 2. Register it from interpreter-setting.json in classpath
         *    {ZEPPELIN_HOME}/interpreter/{interpreter_name}
         */
        if (!registerInterpreterFromPath(interpreterDirString, interpreterJson)) {
          if (!registerInterpreterFromResource(cl, interpreterDirString, interpreterJson)) {
            LOGGER.warn("No interpreter-setting.json found in " + interpreterDirPath);
          }
        }
      }
    } else {
      LOGGER.warn("InterpreterDir {} doesn't exist", interpreterDirPath);
    }

    loadFromFile();
    saveToFile();
  }
项目:cosc111    文件:DirectoryViewer.java   
/**
 * @param args the command line arguments
 */
public static void main(String[] args) throws IOException {
    Scanner cin = new Scanner(System.in);
    System.out.print("Directory Path: ");
    Path dir = Paths.get(cin.nextLine());        
    System.out.print("Filter: ");
    String glob = cin.nextLine().trim();

    if(glob.isEmpty()){
        glob="*";
    }

    Filter<Path> filter = new GlobFilter<>(glob);

    if(Files.isDirectory(dir)){
        for(Path p:Files.newDirectoryStream(dir,filter)){
            BasicFileAttributes attr = Files.readAttributes(p, BasicFileAttributes.class);

            System.out.printf("%s   %s%n", p,
                (attr.isDirectory()?"Directory":"File").toString());    

        }
    }else{
        System.out.println("Not a directory.");
    }

}
项目:test-fs    文件:TestFileSystemProvider.java   
/** {@inheritDoc} */
@Override
public DirectoryStream< Path > newDirectoryStream(Path dir, Filter< ? super Path > filter) throws IOException {

    dir = ((TestPath) dir).unwrap();

    checkIfRemoved(dir);
    checkPermissions(dir, true, AccessMode.READ);

    return provider.newDirectoryStream(dir, filter);
}
项目:ephemeralfs    文件:EphemeralFsFileSystem.java   
DirectoryStream<Path> newDirectoryStream(
        EphemeralFsPath dir,
        EphemeralFsPath relativeDir,
        Filter<? super Path> filter) throws IOException {

    synchronized(fsLock) {
       ResolvedPath resolvedDir = ResolvedPath.resolve(dir);
       if(!resolvedDir.hasTarget()) {
           throw new NoSuchFileException(dir.toString());
       }
       if(!resolvedDir.getTarget().isDir()) {
           throw new NotDirectoryException(dir.toString());
       }

       List<Path> parts = new ArrayList<>();

       for(EphemeralFsPath childName : resolvedDir.getTarget().getChildNames()) {
           Path child = dir.resolve(childName);
           if(filter.accept(child)) {
               parts.add(relativeDir.resolve(child.getFileName()));
           }
       }
       return EphemeralFsSecureDirectoryStream.makeDirectoryStream(
               resolvedDir.getTarget(),
               relativeDir, 
               parts);
    }
}
项目:error-prone    文件:BugPatternFileGenerator.java   
private static void findExamples(
    List<Path> examples, Path dir, DirectoryStream.Filter<Path> filter) throws IOException {
  try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, filter)) {
    for (Path entry : stream) {
      if (Files.isDirectory(entry)) {
        findExamples(examples, entry, filter);
      } else {
        examples.add(entry);
      }
    }
  }
}
项目: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);
    }
}
项目:musicmount    文件:ServerResource.java   
@Override
public DirectoryStream<Resource> newResourceDirectoryStream() throws IOException {
    return newResourceDirectoryStream(new DirectoryStream.Filter<Path>() {
        @Override
        public boolean accept(Path entry) throws IOException {
            return true;
        }
    });
}
项目:truevfs    文件:TFileSystem.java   
DirectoryStream<Path> newDirectoryStream(
        final TPath path,
        final Filter<? super Path> filter)
throws IOException {
    final FsNode entry = stat(path);
    final Set<String> set;
    if (null == entry || null == (set = entry.getMembers()))
        throw new NotDirectoryException(path.toString());

    @NotThreadSafe
    class Adapter implements Iterator<Path> {
        final Iterator<String> it = set.iterator();

        @Override
        public boolean hasNext() {
            return it.hasNext();
        }

        @Override
        public Path next() {
            return path.resolve(it.next());
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    } // Adapter

    @NotThreadSafe
    class FilterIterator extends FilteringIterator<Path> {
        FilterIterator() { super(new Adapter()); }

        @Override
        protected boolean accept(Path element) {
            try {
                return filter.accept(element);
            } catch (IOException ex) {
                throw new DirectoryIteratorException(ex);
            }
        }
    } // FilterIterator

    return  new Stream(new FilterIterator());
}
项目:truevfs    文件:TPath.java   
DirectoryStream<Path> newDirectoryStream(Filter<? super Path> filter)
throws IOException {
    return getFileSystem().newDirectoryStream(this, filter);
}
项目:truevfs    文件:TFileSystemProvider.java   
@Override
public DirectoryStream<Path> newDirectoryStream(Path dir, Filter<? super Path> filter)
throws IOException {
    return promote(dir).newDirectoryStream(filter);
}
项目:openjdk-systemtest    文件:AMemoryFileSystemProvider.java   
@Override
public DirectoryStream<Path> newDirectoryStream(Path dir,
        Filter<? super Path> filter) throws IOException {
    return null;
}
项目:OpenJSharp    文件:ZipPath.java   
DirectoryStream<Path> newDirectoryStream(Filter<? super Path> filter)
    throws IOException
{
    return new ZipDirectoryStream(this, filter);
}
项目:OpenJSharp    文件:ZipFileSystemProvider.java   
@Override
public DirectoryStream<Path> newDirectoryStream(
    Path path, Filter<? super Path> filter) throws IOException
{
    return toZipPath(path).newDirectoryStream(filter);
}
项目:jdk8u-jdk    文件:ZipPath.java   
DirectoryStream<Path> newDirectoryStream(Filter<? super Path> filter)
    throws IOException
{
    return new ZipDirectoryStream(this, filter);
}
项目:jdk8u-jdk    文件:ZipFileSystemProvider.java   
@Override
public DirectoryStream<Path> newDirectoryStream(
    Path path, Filter<? super Path> filter) throws IOException
{
    return toZipPath(path).newDirectoryStream(filter);
}
项目:openjdk-jdk10    文件:JrtPath.java   
final DirectoryStream<Path> newDirectoryStream(Filter<? super Path> filter)
        throws IOException {
    return new JrtDirectoryStream(this, filter);
}
项目:openjdk-jdk10    文件:JrtFileSystemProvider.java   
@Override
public DirectoryStream<Path> newDirectoryStream(
        Path path, Filter<? super Path> filter) throws IOException {
    return toJrtPath(path).newDirectoryStream(filter);
}
项目:openjdk-jdk10    文件:ZipPath.java   
DirectoryStream<Path> newDirectoryStream(Filter<? super Path> filter)
    throws IOException
{
    return new ZipDirectoryStream(this, filter);
}
项目:openjdk-jdk10    文件:ZipFileSystemProvider.java   
@Override
public DirectoryStream<Path> newDirectoryStream(
    Path path, Filter<? super Path> filter) throws IOException
{
    return toZipPath(path).newDirectoryStream(filter);
}
项目:openjdk9    文件:JrtPath.java   
final DirectoryStream<Path> newDirectoryStream(Filter<? super Path> filter)
        throws IOException {
    return new JrtDirectoryStream(this, filter);
}
项目:openjdk9    文件:JrtFileSystemProvider.java   
@Override
public DirectoryStream<Path> newDirectoryStream(
        Path path, Filter<? super Path> filter) throws IOException {
    return toJrtPath(path).newDirectoryStream(filter);
}
项目:openjdk9    文件:ZipPath.java   
DirectoryStream<Path> newDirectoryStream(Filter<? super Path> filter)
    throws IOException
{
    return new ZipDirectoryStream(this, filter);
}
项目:openjdk9    文件:ZipFileSystemProvider.java   
@Override
public DirectoryStream<Path> newDirectoryStream(
    Path path, Filter<? super Path> filter) throws IOException
{
    return toZipPath(path).newDirectoryStream(filter);
}