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);
}
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;
}
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());
}
}
}
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;
}
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;
}
Aggregations