List of usage examples for java.nio.file FileSystem getPathMatcher
public abstract PathMatcher getPathMatcher(String syntaxAndPattern);
From source file:Main.java
public static void main(String[] args) throws IOException { FileSystem fileSystem = FileSystems.getDefault(); PathMatcher matcher = fileSystem.getPathMatcher("glob:java?.exe"); }
From source file:ch.bender.evacuate.Runner.java
/** * initExcludeMatchers/*from w ww . j a va2s.co m*/ * <p> */ private void initExcludeMatchers() { FileSystem fs = myBackupDir.getFileSystem(); myExclusionMatchers = myExcludePatterns.stream().filter(s -> (s != null && s.length() > 0)) .map(s -> fs.getPathMatcher("glob:" + s)).collect(Collectors.toList()); }
From source file:com.aol.advertising.qiao.injector.file.watcher.QiaoFileManager.java
private void _setupFileRenameMatcher() throws Exception { FileSystem fileSystem = FileSystems.getDefault(); pathMatcher = fileSystem.getPathMatcher("glob:**/" + candidateFilesPatternForRename); }
From source file:com.spotify.docker.client.CompressedDirectory.java
@VisibleForTesting static PathMatcher goPathMatcher(FileSystem fs, String pattern) { // Supposed to work the same way as Go's path.filepath.match.Match: // http://golang.org/src/path/filepath/match.go#L34 final String notSeparatorPattern = getNotSeparatorPattern(fs.getSeparator()); final String starPattern = String.format("%s*", notSeparatorPattern); final StringBuilder patternBuilder = new StringBuilder(); boolean inCharRange = false; boolean inEscape = false; // This is of course hugely inefficient, but it passes most of the test suite, TDD ftw... for (int i = 0; i < pattern.length(); i++) { final char c = pattern.charAt(i); if (inCharRange) { if (inEscape) { patternBuilder.append(c); inEscape = false;/*from w w w .j a v a2 s . c o m*/ } else { switch (c) { case '\\': patternBuilder.append('\\'); inEscape = true; break; case ']': patternBuilder.append(']'); inCharRange = false; break; default: patternBuilder.append(c); } } } else { if (inEscape) { patternBuilder.append(Pattern.quote(Character.toString(c))); inEscape = false; } else { switch (c) { case '*': patternBuilder.append(starPattern); break; case '?': patternBuilder.append(notSeparatorPattern); break; case '[': patternBuilder.append("["); inCharRange = true; break; case '\\': inEscape = true; break; default: patternBuilder.append(Pattern.quote(Character.toString(c))); } } } } return fs.getPathMatcher("regex:" + patternBuilder.toString()); }
From source file:org.openeos.tools.maven.plugins.GenerateEntitiesMojo.java
private List<File> findLiquibaseFiles(Artifact artifact) throws IOException { if (artifact == null) { return Collections.emptyList(); }//from w w w . ja v a2 s . c om List<File> result = new ArrayList<File>(); if (artifact.getType().equals("jar")) { File file = artifact.getFile(); FileSystem fs = FileSystems.newFileSystem(Paths.get(file.getAbsolutePath()), this.getClass().getClassLoader()); PathMatcher matcher = fs.getPathMatcher("glob:" + searchpath); JarFile jarFile = new JarFile(file); Enumeration<JarEntry> entries = jarFile.entries(); TreeSet<JarEntry> setEntries = new TreeSet<JarEntry>(new Comparator<JarEntry>() { @Override public int compare(JarEntry o1, JarEntry o2) { return o1.getName().compareTo(o2.getName()); } }); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); if (matcher.matches(fs.getPath(entry.getName()))) { setEntries.add(entry); } } for (JarEntry entry : setEntries) { File resultFile = File.createTempFile("generate-entities-maven", ".xml"); FileOutputStream out = new FileOutputStream(resultFile); InputStream in = jarFile.getInputStream(entry); IOUtils.copy(in, out); in.close(); out.close(); result.add(resultFile); } jarFile.close(); } return result; }