Search in sources :

Example 46 with PathMatcher

use of java.nio.file.PathMatcher in project elasticsearch by elastic.

the class IngestUserAgentPlugin method createUserAgentParsers.

static Map<String, UserAgentParser> createUserAgentParsers(Path userAgentConfigDirectory, UserAgentCache cache) throws IOException {
    Map<String, UserAgentParser> userAgentParsers = new HashMap<>();
    UserAgentParser defaultParser = new UserAgentParser(DEFAULT_PARSER_NAME, IngestUserAgentPlugin.class.getResourceAsStream("/regexes.yaml"), cache);
    userAgentParsers.put(DEFAULT_PARSER_NAME, defaultParser);
    if (Files.exists(userAgentConfigDirectory) && Files.isDirectory(userAgentConfigDirectory)) {
        PathMatcher pathMatcher = userAgentConfigDirectory.getFileSystem().getPathMatcher("glob:**.yaml");
        try (Stream<Path> regexFiles = Files.find(userAgentConfigDirectory, 1, (path, attr) -> attr.isRegularFile() && pathMatcher.matches(path))) {
            Iterable<Path> iterable = regexFiles::iterator;
            for (Path path : iterable) {
                String parserName = path.getFileName().toString();
                try (InputStream regexStream = Files.newInputStream(path, StandardOpenOption.READ)) {
                    userAgentParsers.put(parserName, new UserAgentParser(parserName, regexStream, cache));
                }
            }
        }
    }
    return Collections.unmodifiableMap(userAgentParsers);
}
Also used : Path(java.nio.file.Path) PathMatcher(java.nio.file.PathMatcher) HashMap(java.util.HashMap) InputStream(java.io.InputStream)

Example 47 with PathMatcher

use of java.nio.file.PathMatcher in project jphp by jphp-compiler.

the class FileObject method matches.

@Signature(@Arg("pattern"))
public Memory matches(Environment env, Memory... args) {
    FileSystem aDefault = FileSystems.getDefault();
    PathMatcher pathMatcher = aDefault.getPathMatcher(args[0].toString());
    return pathMatcher.matches(aDefault.getPath(file.getPath())) ? Memory.TRUE : Memory.FALSE;
}
Also used : PathMatcher(java.nio.file.PathMatcher) FileSystem(java.nio.file.FileSystem)

Example 48 with PathMatcher

use of java.nio.file.PathMatcher in project neo4j by neo4j.

the class SpecSuiteResources method findAndUnpackTo.

private static void findAndUnpackTo(FileSystem sourceFileSystem, Path sourceRootDirectory, String sourceFilePattern, File targetDirectory) throws IOException {
    System.out.println("Unpacking to " + targetDirectory.getCanonicalPath());
    PathMatcher matcher = sourceFileSystem.getPathMatcher(sourceFilePattern);
    for (Iterator<Path> it = Files.walk(sourceRootDirectory, 3).iterator(); it.hasNext(); ) {
        Path next = it.next();
        if (matcher.matches(next)) {
            File target = new File(targetDirectory, next.getFileName().toString());
            Files.copy(next, target.toPath(), StandardCopyOption.REPLACE_EXISTING);
            System.out.println("Unpacked " + target.getName());
        }
    }
}
Also used : Path(java.nio.file.Path) PathMatcher(java.nio.file.PathMatcher) File(java.io.File)

Example 49 with PathMatcher

use of java.nio.file.PathMatcher in project JMRI by JMRI.

the class FileLineEndingsTest method getFiles.

/**
     * Get all files with the given prefixes in a directory and validate them.
     *
     * @param directory the directory containing the files
     * @param patterns  glob patterns of files to match
     * @return a collection of files to validate
     */
public static Collection<Object[]> getFiles(File directory, String[] patterns) {
    // setup logging early so this method can log
    Log4JFixture.setUp();
    ArrayList<Object[]> files = new ArrayList<>();
    try {
        for (String pattern : patterns) {
            PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:" + pattern);
            // ignore the build directory if immediately under the passed in directory
            PathMatcher target = FileSystems.getDefault().getPathMatcher("glob:./target/**");
            Files.walk(directory.toPath()).filter(path -> !target.matches(path)).filter(matcher::matches).forEach((path) -> {
                if (path.toFile().isFile()) {
                    files.add(new Object[] { path.toFile() });
                }
            });
        }
    } catch (IOException ex) {
        log.error("Unable to get files in {}", directory, ex);
    }
    return files;
}
Also used : PathMatcher(java.nio.file.PathMatcher) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 50 with PathMatcher

use of java.nio.file.PathMatcher in project repairnator by Spirals-Team.

the class EvaluatePotentialBug method getJsonFromDirectory.

private Collection<File> getJsonFromDirectory(String path) throws IOException {
    List<File> result = new ArrayList<>();
    File file = new File(path);
    PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:**.json");
    for (Path p : Files.newDirectoryStream(file.toPath())) {
        if (p.toFile().isFile() && matcher.matches(p)) {
            result.add(p.toFile());
        }
    }
    return result;
}
Also used : Path(java.nio.file.Path) PathMatcher(java.nio.file.PathMatcher) ArrayList(java.util.ArrayList) File(java.io.File)

Aggregations

PathMatcher (java.nio.file.PathMatcher)87 Path (java.nio.file.Path)40 Test (org.junit.Test)23 IOException (java.io.IOException)22 File (java.io.File)16 ArrayList (java.util.ArrayList)12 FileSystem (java.nio.file.FileSystem)11 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)10 FileVisitResult (java.nio.file.FileVisitResult)9 Files (java.nio.file.Files)5 Paths (java.nio.file.Paths)5 HashSet (java.util.HashSet)5 List (java.util.List)5 ProjectHandlerRegistry (org.eclipse.che.api.project.server.handlers.ProjectHandlerRegistry)5 ProjectImporterRegistry (org.eclipse.che.api.project.server.importer.ProjectImporterRegistry)5 ProjectTypeRegistry (org.eclipse.che.api.project.server.type.ProjectTypeRegistry)5 DefaultFileWatcherNotificationHandler (org.eclipse.che.api.vfs.impl.file.DefaultFileWatcherNotificationHandler)5 FileTreeWatcher (org.eclipse.che.api.vfs.impl.file.FileTreeWatcher)5 LocalVirtualFileSystemProvider (org.eclipse.che.api.vfs.impl.file.LocalVirtualFileSystemProvider)5 FSLuceneSearcherProvider (org.eclipse.che.api.vfs.search.impl.FSLuceneSearcherProvider)5