Package java.nio.file

Examples of java.nio.file.PathMatcher.matches()


        final PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:**");
         DirectoryStream.Filter<Path> filter = new DirectoryStream.Filter<Path>() {
            @Override
            public boolean accept(Path entry)  {
                return matcher.matches(entry.getFileName());
            }
        };

        if(starPattern.matcher(searchArgument).matches()) {
            try (DirectoryStream<Path> stream = Files.newDirectoryStream(incPath.toPath(), new DirectoryFilter())) {
View Full Code Here


        final PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:**");
         DirectoryStream.Filter<Path> filter = new DirectoryStream.Filter<Path>() {
            @Override
            public boolean accept(Path entry)  {
                return matcher.matches(entry.getFileName());
            }
        };

        if(starPattern.matcher(searchArgument).matches()) {
            try (DirectoryStream<Path> stream = findDirectory ?
View Full Code Here

      final PathMatcher matcher = fs.getPathMatcher("glob:" + pattern);
      java.nio.file.Files.walkFileTree(
          fs.getPath(prefix), new SimpleFileVisitor<Path>() {
            @Override public FileVisitResult visitFile(
                Path p, BasicFileAttributes attrs) {
              if (matcher.matches(p)) {
                if (remove) {
                  allJsInputs.remove(p.toString());
                } else {
                  allJsInputs.add(p.toString());
                }
View Full Code Here

        final PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:**");
         DirectoryStream.Filter<Path> filter = new DirectoryStream.Filter<Path>() {
            @Override
            public boolean accept(Path entry)  {
                return matcher.matches(entry.getFileName());
            }
        };

        if(starPattern.matcher(searchArgument).matches()) {
            try (DirectoryStream<Path> stream = findDirectory ?
View Full Code Here

        {
            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
                    throws IOException
            {
                if (matcher.matches(file)) {
                    list.add(file);
                }
                return FileVisitResult.CONTINUE;
            }
        });
View Full Code Here

  /**
   * Asserts that the path matches the given syntax and pattern.
   */
  public PathSubject matches(String syntaxAndPattern) {
    PathMatcher matcher = getSubject().getFileSystem().getPathMatcher(syntaxAndPattern);
    if (!matcher.matches(getSubject())) {
      fail("matches", syntaxAndPattern);
    }
    return this;
  }

View Full Code Here

  /**
   * Asserts that the path does not match the given syntax and pattern.
   */
  public PathSubject doesNotMatch(String syntaxAndPattern) {
    PathMatcher matcher = getSubject().getFileSystem().getPathMatcher(syntaxAndPattern);
    if (matcher.matches(getSubject())) {
      fail("does not match", syntaxAndPattern);
    }
    return this;
  }

View Full Code Here

    Assert.assertEquals(1, paths.size()); // Note that search is not recursive
    Assert.assertEquals(pFile1Txt, paths.get(0));
   
    // Use PathMatcher
    PathMatcher pm1 = FileSystems.getDefault().getPathMatcher("glob:*"); // Note that we need the glob prefix here
    Assert.assertFalse(pm1.matches(pFile1Txt)); // Note that * doesn't cross directory boundaries
    Assert.assertTrue(pm1.matches(pFile1Txt.getFileName()));

    // ** crosses directory boundaries
    Assert.assertTrue(FileSystems.getDefault().getPathMatcher("glob:**").matches(pFile1Txt));
   
 
View Full Code Here

    Assert.assertEquals(pFile1Txt, paths.get(0));
   
    // Use PathMatcher
    PathMatcher pm1 = FileSystems.getDefault().getPathMatcher("glob:*"); // Note that we need the glob prefix here
    Assert.assertFalse(pm1.matches(pFile1Txt)); // Note that * doesn't cross directory boundaries
    Assert.assertTrue(pm1.matches(pFile1Txt.getFileName()));

    // ** crosses directory boundaries
    Assert.assertTrue(FileSystems.getDefault().getPathMatcher("glob:**").matches(pFile1Txt));
   
    // Multi Matches
View Full Code Here

    Assert.assertTrue(FileSystems.getDefault().getPathMatcher("glob:**.{txt,sql}").matches(pFile1Txt));
    Assert.assertFalse(FileSystems.getDefault().getPathMatcher("glob:**.{html,xml}").matches(pFile1Txt));
   
    // Complex Matches
    PathMatcher pm2 = FileSystems.getDefault().getPathMatcher("glob:**/sub/sub[A-F]ile?.{txt,bak}");
    Assert.assertFalse(pm2.matches(pFile1Txt));
    Assert.assertTrue(pm2.matches(pSubFile1Txt));
  }
 
  private static class SuppressedExceptionTest implements AutoCloseable {
    private String closeExceptionMsg;
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.