List of usage examples for org.apache.commons.io FilenameUtils wildcardMatch
public static boolean wildcardMatch(String filename, String wildcardMatcher, IOCase caseSensitivity)
From source file:net.sf.jvifm.model.filter.PathFilter.java
public boolean accept(File file) { String path = file.getPath(); if (FilenameUtils.wildcardMatch(path, wildcard, IOCase.INSENSITIVE)) { return true; }//from w w w . j a v a2 s . c om return false; }
From source file:com.jkoolcloud.tnt4j.streams.inputs.HdfsFileLineStream.java
/** * Searches for files matching name pattern. Name pattern also may contain path of directory, where file search * should be performed, e.g., C:/Tomcat/logs/localhost_access_log.*.txt. If no path is defined (just file name * pattern) then files are searched in {@code System.getProperty("user.dir")}. Files array is ordered by file create * timestamp in descending order.//from w w w. ja v a 2 s . c om * * @param path * path of file * @param fs * file system * * @return array of found files paths. * @throws IOException * if files can't be listed by file system. * * @see FileSystem#listStatus(Path, PathFilter) * @see FilenameUtils#wildcardMatch(String, String, IOCase) */ public static Path[] searchFiles(Path path, FileSystem fs) throws IOException { FileStatus[] dir = fs.listStatus(path.getParent(), new PathFilter() { @Override public boolean accept(Path path) { String name = path.getName(); return FilenameUtils.wildcardMatch(name, "*", IOCase.INSENSITIVE); // NON-NLS } }); Path[] activityFiles = new Path[dir == null ? 0 : dir.length]; if (dir != null) { Arrays.sort(dir, new Comparator<FileStatus>() { @Override public int compare(FileStatus o1, FileStatus o2) { return Long.valueOf(o1.getModificationTime()).compareTo(o2.getModificationTime()) * (-1); } }); for (int i = 0; i < dir.length; i++) { activityFiles[i] = dir[i].getPath(); } } return activityFiles; }
From source file:modmanager.backend.ModificationOption.java
private void load(File path) { logger.log(Level.FINE, "Modification option requested for {0}", path.getAbsolutePath()); /**/*w w w . j a v a 2s .c om*/ * Set name */ name = path.getName(); /** * Make compatible */ makeUnixCompatible(path); /** * Declare if data rooted or main dir rooted */ if ((new File(path, "Data")).exists()) { rootDirectory = ""; } else { rootDirectory = "Data"; } /** * Look in files */ for (File file : FileUtils.listFiles(path, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)) { if (!file.isDirectory()) { if (file.getParentFile().getName().equalsIgnoreCase("fomod")) { continue; } else if (FilenameUtils.wildcardMatch(file.getName(), "*.txt", IOCase.INSENSITIVE)) { continue; } else if (FilenameUtils.wildcardMatch(file.getName(), "*.rtf", IOCase.INSENSITIVE)) { continue; } else if (FilenameUtils.wildcardMatch(file.getName(), "*.pdf", IOCase.INSENSITIVE)) { continue; } else if (FilenameUtils.wildcardMatch(file.getName(), "*.jskmm_status", IOCase.INSENSITIVE)) { continue; } getFiles().add(file); logger.log(Level.FINE, "... added {0} to option", Util.relativePath(path, file)); } } }
From source file:net.sf.jvifm.util.AutoCompleteUtil.java
public static List<File> getFileCompleteList(String pwd, String path, boolean onlyDir) { List<File> list = new ArrayList<File>(); String fileName = new File(path).getName(); if (path.endsWith(":")) return null; File file = new File(FilenameUtils.concat(pwd, path)); File pwdFile = null;/*w w w. j ava2 s . c o m*/ pwdFile = file; if (path.endsWith(File.separator) || path.trim().equals("")) { pwdFile = file; } else { if (file.getParent() == null) return null; pwdFile = new File(file.getParent()); } if (!pwdFile.exists()) return null; File[] files = pwdFile.listFiles((FileFilter) Util.getDefaultFileFilter()); if (files == null || files.length <= 0) return null; boolean lowerCase = false; if (fileName.toLowerCase().equals(fileName)) { lowerCase = true; } for (int i = 0; i < files.length; i++) { String tmpFileName = files[i].getName(); if (lowerCase) tmpFileName = tmpFileName.toLowerCase(); if (tmpFileName.startsWith(fileName) || path.endsWith(File.separator) || FilenameUtils.wildcardMatch(tmpFileName, fileName, IOCase.INSENSITIVE)) if (onlyDir) { if (files[i].isDirectory()) list.add(files[i]); } else { list.add(files[i]); } } if (list.size() <= 0) return null; return list; }
From source file:com.thoughtworks.go.config.rules.AbstractDirective.java
protected boolean matchesResource(String resource) { if (equalsIgnoreCase("*", this.resource)) { return true; }//from ww w.ja v a 2 s . c om return FilenameUtils.wildcardMatch(resource, this.resource, IOCase.INSENSITIVE); }
From source file:com.cloudbees.plugins.credentials.domains.HostnameSpecification.java
/** * {@inheritDoc}/*from w ww .j a v a 2s . c o m*/ */ @NonNull @Override public Result test(@NonNull DomainRequirement requirement) { if (requirement instanceof HostnameRequirement) { String hostname = ((HostnameRequirement) requirement).getHostname(); if (includes != null) { boolean isInclude = false; for (String include : includes.split("[,\\n ]")) { include = Util.fixEmptyAndTrim(include); if (include == null) { continue; } if (FilenameUtils.wildcardMatch(hostname, include, IOCase.INSENSITIVE)) { isInclude = true; break; } } if (!isInclude) { return Result.NEGATIVE; } } if (excludes != null) { boolean isExclude = false; for (String exclude : excludes.split("[,\\n ]")) { exclude = Util.fixEmptyAndTrim(exclude); if (exclude == null) { continue; } if (FilenameUtils.wildcardMatch(hostname, exclude, IOCase.INSENSITIVE)) { isExclude = true; break; } } if (isExclude) { return Result.NEGATIVE; } } return Result.PARTIAL; } return Result.UNKNOWN; }
From source file:com.cloudbees.plugins.credentials.domains.HostnamePortSpecification.java
/** * {@inheritDoc}//from w w w . ja va 2s .c o m */ @NonNull @Override public Result test(@NonNull DomainRequirement requirement) { if (requirement instanceof HostnamePortRequirement) { String hostPort = ((HostnamePortRequirement) requirement).getHostname() + ":" + ((HostnamePortRequirement) requirement).getPort(); if (includes != null) { boolean isInclude = false; for (String include : includes.split("[,\\n ]")) { include = Util.fixEmptyAndTrim(include); if (include == null) { continue; } if (include.indexOf(':') == -1) { include = include + ":*"; } if (FilenameUtils.wildcardMatch(hostPort, include, IOCase.INSENSITIVE)) { isInclude = true; break; } } if (!isInclude) { return Result.NEGATIVE; } } if (excludes != null) { boolean isExclude = false; for (String exclude : excludes.split("[,\\n ]")) { exclude = Util.fixEmptyAndTrim(exclude); if (exclude == null) { continue; } if (exclude.indexOf(':') == -1) { exclude = exclude + ":*"; } if (FilenameUtils.wildcardMatch(hostPort, exclude, IOCase.INSENSITIVE)) { isExclude = true; break; } } if (isExclude) { return Result.NEGATIVE; } } } else if (requirement instanceof HostnameRequirement) { // if the requirement is only for a hostname we can still match some of the spec. String hostname = ((HostnameRequirement) requirement).getHostname(); if (includes != null) { boolean isInclude = false; for (String include : includes.split("[,\\n ]")) { include = Util.fixEmptyAndTrim(include); if (include == null) { continue; } int index = include.indexOf(":"); if (index != -1) { include = include.substring(0, index); } if (FilenameUtils.wildcardMatch(hostname, include, IOCase.INSENSITIVE)) { isInclude = true; break; } } if (!isInclude) { return Result.NEGATIVE; } } if (excludes != null) { boolean isExclude = false; for (String exclude : excludes.split("[,\\n ]")) { exclude = Util.fixEmptyAndTrim(exclude); if (exclude == null) { continue; } int index = exclude.indexOf(":"); if (index != -1) { exclude = exclude.substring(0, index); } if (FilenameUtils.wildcardMatch(hostname, exclude, IOCase.INSENSITIVE)) { isExclude = true; break; } } if (isExclude) { return Result.NEGATIVE; } } } return Result.UNKNOWN; }
From source file:modmanager.backend.Modification.java
private void load(File path) { logger.log(Level.INFO, "Loading modification from {0}", path.getAbsolutePath()); if (!path.isDirectory()) { return;//from w ww. jav a2 s.c om } /** * Precheck: dir empty? (failed extraction) */ if (path.list().length == 0) { path.delete(); return; } /** * Precheck: archive ghost dir? */ { File[] entries = path.listFiles(); if (entries.length == 1) { File one = entries[0]; if (one.isDirectory()) { if (!one.getName().equalsIgnoreCase("data")) { try { logger.log(Level.INFO, "Moving directory, because someone decided it's good to pack all data into a sub directory ..."); /** * It's a directory. Change filesystem by * reparenting */ File tmp = new File(path.getAbsolutePath() + ".tmp"); FileUtils.moveDirectory(one, tmp); FileUtils.deleteDirectory(path); FileUtils.moveDirectory(tmp, path); } catch (IOException ex) { logger.log(Level.SEVERE, ex.getMessage()); return; } } } } } this.directory = path; /** * Read name */ this.name = path.getName(); /** * Wizard indicates */ if ((new File(path, "Wizard.txt")).exists()) { this.type = Type.MULTIOPTION; } else { this.type = Type.MULTIOPTION; for (File sub : path.listFiles()) { if (FilenameUtils.wildcardMatch(sub.getName(), "*.bsa", IOCase.INSENSITIVE)) { this.type = Type.SIMPLE; break; } else if (FilenameUtils.wildcardMatch(sub.getName(), "*.esp", IOCase.INSENSITIVE)) { this.type = Type.SIMPLE; break; } else if (FilenameUtils.wildcardMatch(sub.getName(), "Meshes", IOCase.INSENSITIVE)) { this.type = Type.SIMPLE; break; } else if (FilenameUtils.wildcardMatch(sub.getName(), "Textures", IOCase.INSENSITIVE)) { this.type = Type.SIMPLE; break; } else if (FilenameUtils.wildcardMatch(sub.getName(), "data", IOCase.INSENSITIVE)) { this.type = Type.SIMPLE; break; } } } logger.log(Level.INFO, "... mod type detected: {0}", this.type); /** * OK, load the mod types from given type */ switch (this.type) { /** * This is intended! */ case MULTIOPTION: { for (File sub : path.listFiles()) { if (sub.isDirectory() && !sub.getName().equalsIgnoreCase("fomod") && !sub.getName().toLowerCase().contains("readme") && !sub.getName().toLowerCase().contains("manual")) { ModificationOption opt = new ModificationOption(this, sub); if (opt.getFileCount() != 0) { options.put(opt.getName(), opt); } } } } break; case SIMPLE: { //Create new option based on modification path ModificationOption opt = new ModificationOption(this, path); if (opt.getFileCount() != 0) { options.put(opt.getName(), opt); } } break; } /** * Load screenshots */ for (File file : getScreenshotImages()) { status.addScreenshotImage(file); } if (!options.isEmpty()) { loaded = true; } else { logger.log(Level.WARNING, "Ignoring {0}: Empty!", name); } }
From source file:net.sf.jvifm.util.AutoCompleteUtil.java
@SuppressWarnings("all") public static String[] getBookmarkFileOptions(String name) { ArrayList result = new ArrayList(); BookmarkManager bookmarkManager = BookmarkManager.getInstance(); boolean lowerCase = false; if (name.toLowerCase().equals(name)) { lowerCase = true;/*ww w. j av a 2 s .com*/ } List bookmarkList = bookmarkManager.getAll(); if (bookmarkList != null) { for (Iterator it = bookmarkList.iterator(); it.hasNext();) { Bookmark bookmark = (Bookmark) it.next(); String bookmarkName = bookmark.getName(); if (lowerCase) { bookmarkName = bookmarkName.toLowerCase(); } if (FilenameUtils.wildcardMatch(bookmarkName, name, IOCase.INSENSITIVE) || bookmarkName.startsWith(name)) { result.add(bookmark.getPath()); } } } if (result.size() <= 0) return null; String[] resultArray = new String[result.size()]; for (int i = 0; i < resultArray.length; i++) { resultArray[i] = (String) result.get(i); } return resultArray; }
From source file:net.sf.jvifm.util.AutoCompleteUtil.java
@SuppressWarnings("all") public static Shortcut[] getShortcutsCompleteList2(String cmd) { ArrayList result = new ArrayList(); ShortcutsManager scm = ShortcutsManager.getInstance(); boolean lowerCase = false; if (cmd.toLowerCase().equals(cmd)) { lowerCase = true;//from w w w. ja v a2 s.c om } ArrayList customCmdNameList = scm.getAll(); if (customCmdNameList != null) { for (Iterator it = customCmdNameList.iterator(); it.hasNext();) { Shortcut shortcut = (Shortcut) it.next(); String cmdName = shortcut.getName(); if (lowerCase) { cmdName = cmdName.toLowerCase(); } if (FilenameUtils.wildcardMatch(cmdName, cmd, IOCase.INSENSITIVE) || cmdName.startsWith(cmd)) { result.add(shortcut); } } } if (result.size() <= 0) return null; Shortcut[] resultArray = new Shortcut[result.size()]; for (int i = 0; i < resultArray.length; i++) { resultArray[i] = (Shortcut) result.get(i); } return resultArray; }