List of usage examples for org.apache.commons.io IOCase SENSITIVE
IOCase SENSITIVE
To view the source code for org.apache.commons.io IOCase SENSITIVE.
Click Source Link
From source file:com.qwazr.utils.WildcardMatcher.java
/** * Match the passed name with the current pattern * * @param name the string to test * @param caseSensitivity// w w w . j av a 2 s . c o m * @return true if the name match the pattern */ public boolean match(String name, IOCase caseSensitivity) { if (name == null && wcs == null) { return true; } if (name == null || wcs == null) { return false; } if (caseSensitivity == null) { caseSensitivity = IOCase.SENSITIVE; } int length = name.length(); boolean anyChars = false; int textIdx = 0; int wcsIdx = 0; Stack<int[]> backtrack = new Stack<int[]>(); // loop around a backtrack stack, to handle complex * matching do { if (backtrack.size() > 0) { int[] array = backtrack.pop(); wcsIdx = array[0]; textIdx = array[1]; anyChars = true; } // loop whilst tokens and text left to process while (wcsIdx < wcs.length) { if (wcs[wcsIdx].equals("?")) { // ? so move to next text char textIdx++; if (textIdx > length) { break; } anyChars = false; } else if (wcs[wcsIdx].equals("*")) { // set any chars status anyChars = true; if (wcsIdx == wcs.length - 1) { textIdx = length; } } else { // matching text token if (anyChars) { // any chars then try to locate text token textIdx = caseSensitivity.checkIndexOf(name, textIdx, wcs[wcsIdx]); if (textIdx == -1) { // token not found break; } int repeat = caseSensitivity.checkIndexOf(name, textIdx + 1, wcs[wcsIdx]); if (repeat >= 0) { backtrack.push(new int[] { wcsIdx, repeat }); } } else { // matching from current position if (!caseSensitivity.checkRegionMatches(name, textIdx, wcs[wcsIdx])) { // couldnt match token break; } } // matched text token, move text index to end of matched token textIdx += wcs[wcsIdx].length(); anyChars = false; } wcsIdx++; } // full match if (wcsIdx == wcs.length && textIdx == length) { return true; } } while (backtrack.size() > 0); return false; }
From source file:com.mucommander.commons.file.filter.WildcardFileFilter.java
/** * Creates a new <code>WildcardFileFilter</code> operating in the specified mode. * * @param s the wildcard to match//from ww w.j a va2 s.c om * @param caseSensitive if true, this FilenameFilter will be case-sensitive * @param inverted if true, this filter will operate in inverted mode. */ public WildcardFileFilter(String s, boolean caseSensitive, boolean inverted) { super(new FilenameGenerator(), caseSensitive, inverted); this.fileFilter = new org.apache.commons.io.filefilter.WildcardFileFilter(s, isCaseSensitive() ? IOCase.SENSITIVE : IOCase.INSENSITIVE); }
From source file:gobblin.util.filesystem.PathAlterationObserver.java
/** * The comparison between path is always case-sensitive in this general file system context. *///from ww w . ja va 2s . c o m public PathAlterationObserver(final FileStatusEntry rootEntry, final PathFilter pathFilter) throws IOException { if (rootEntry == null) { throw new IllegalArgumentException("Root entry is missing"); } if (rootEntry.getPath() == null) { throw new IllegalArgumentException("Root directory is missing"); } this.rootEntry = rootEntry; this.pathFilter = pathFilter; this.fs = rootEntry.getPath().getFileSystem(new Configuration()); // By default, the comparsion is case sensitive. this.comparator = new Comparator<Path>() { @Override public int compare(Path o1, Path o2) { return IOCase.SENSITIVE.checkCompareTo(o1.toUri().toString(), o2.toUri().toString()); } }; }
From source file:at.gv.egiz.pdfas.lib.settings.Settings.java
private void loadSettingsRecursive(File workDirectory, File file) throws PdfAsSettingsException { String configDir = workDirectory.getAbsolutePath() + File.separator + CFG_DIR; logger.debug("Loading: " + file.getName()); try (InputStream in = new FileInputStream(file)) { Properties tmpProps = new Properties(); tmpProps.load(in);//from w w w . ja va2s . co m properties.putAll(tmpProps); Map<String, String> includes = this.getValuesPrefix(INCLUDE, tmpProps); File contextFolder = new File(configDir); if (includes != null) { Iterator<String> includeIterator = includes.values().iterator(); while (includeIterator.hasNext()) { contextFolder = new File(configDir); String includeFileName = includeIterator.next(); File includeInstruction = new File(contextFolder, includeFileName); contextFolder = includeInstruction.getParentFile(); String includeName = includeInstruction.getName(); WildcardFileFilter fileFilter = new WildcardFileFilter(includeName, IOCase.SENSITIVE); Collection<File> includeFiles = null; if (contextFolder != null && contextFolder.exists() && contextFolder.isDirectory()) { includeFiles = FileUtils.listFiles(contextFolder, fileFilter, null); } if (includeFiles != null && !includeFiles.isEmpty()) { logger.debug("Including '" + includeFileName + "'."); for (File includeFile : includeFiles) { loadSettingsRecursive(workDirectory, includeFile); } } } } } catch (IOException e) { throw new PdfAsSettingsException("Failed to read settings!", e); } }
From source file:com.github.aliteralmind.codelet.util.FilenameBlackWhiteList.java
/** <p>Creates a new white-or-blacklist from a set of string-variables as found in a configuration text file.</p> //w w w .j a v a2 s .c o m * @param black_white_off Is this a {@linkplain com.github.aliteralmind.codelet.util.BlackOrWhite#BLACK blacklist}, {@linkplain com.github.aliteralmind.codelet.util.BlackOrWhite#WHITE whitelist}, or nothing? Must be {@code "black"}, {@code "white"}, or {@code "off"} (the case of this parameter's value is ignored). If {@code "off"}, this function <i><b>returns</b></i> a new {@code FilenameBlackWhiteList} that {@linkplain #newForAcceptAll(Appendable) accepts everything}. * @param ignore_require_system Should case be {@linkplain org.apache.commons.io.IOCase#INSENSITIVE ignored}, {@linkplain org.apache.commons.io.IOCase#SENSITIVE <i>not</i> ignored}, or determined by the operating {@linkplain org.apache.commons.io.IOCase#SYSTEM system}? Must be {@code "ignore"}, {@code "require"}, or {@code "system"} (the case of <i>this parameter's value</i> is ignored). * @param separator The character used to separate each proper and override value. Such as a comma ({@code ","}), {@linkplain com.github.xbn.lang.XbnConstants#LINE_SEP line-separator} ({@code "\r\n"}), or tab ({@code "\t"}). May not be {@code null}, empty, or contain any letters, digits, underscores ({@code '_'}), question-marks ({@code '?'}), or asterisks ({@code '*'}). * @param separated_propers The separated list of "proper" items. Must be separated by {@code separator}, and otherwise must conform to the restrictions for the {@link #FilenameBlackWhiteList(BlackOrWhite, IOCase, String[], String[], Appendable) proper_items} constructor parameter. * @param separated_overrides The separated list of override items. Must be non-{@code null} (if none, this must be the empty string: {@code ""}), separated by {@code separator}, and otherwise must conform to the restrictions for the {@code override_items} constructor parameter. * @see #newFromProperties(Properties, String, String, String, String, String, Appendable, Appendable) newFromProperties */ public static final FilenameBlackWhiteList newFromConfigStringVars(String black_white_off, String ignore_require_system, String separator, String separated_propers, String separated_overrides, Appendable dbgLoading_ifNonNull, Appendable dbgAccept_ifNonNull) { TextAppenter dbgAptr = NewTextAppenterFor.appendableUnusableIfNull(dbgLoading_ifNonNull); if (dbgAptr.isUseable()) { dbgAptr.appentln("FilenameBlackWhiteList newFromConfigStringVars:"); } try { if (black_white_off.toLowerCase().equals("off")) { if (dbgAptr.isUseable()) { dbgAptr.appentln(" - newForAcceptAll(dbgAccept_ifNonNull). DONE"); } return newForAcceptAll(dbgAccept_ifNonNull); } } catch (RuntimeException rx) { throw CrashIfObject.nullOrReturnCause(black_white_off, "black_white_off", null, rx); } BlackOrWhite bw = EnumUtil.toValueWithNullDefault(black_white_off, "black_white_off", IgnoreCase.YES, DefaultValueFor.NOTHING, BlackOrWhite.BLACK); if (dbgAptr.isUseable()) { dbgAptr.appentln(" - BlackOrWhite." + bw); } IOCase ioc = null; try { switch (ignore_require_system.toUpperCase()) { case "IGNORE": ioc = IOCase.INSENSITIVE; break; case "REQUIRE": ioc = IOCase.SENSITIVE; break; case "SYSTEM": ioc = IOCase.SYSTEM; break; default: throw new IllegalArgumentException( "ignore_require_system.toUpperCase() (\"" + ignore_require_system.toUpperCase() + "\") does not equal \"IGNORE\", \"REQUIRE\", or \"SYSTEM\"."); } } catch (RuntimeException rx) { throw CrashIfObject.nullOrReturnCause(ignore_require_system, "ignore_require_system", null, rx); } if (dbgAptr.isUseable()) { dbgAptr.appentln(" - IOCase." + ioc); } CrashIfString.nullEmpty(separator, "separator", null); if (Pattern.compile("[?*\\w]").matcher(separator).find()) { throw new IllegalArgumentException("separator (\"" + separator + "\") contains an illegal character."); } if (dbgAptr.isUseable()) { dbgAptr.appentln(" - separator valid: \"" + separator + "\""); } String[] propers = null; try { propers = separated_propers.split(separator); } catch (RuntimeException rx) { throw CrashIfObject.nullOrReturnCause(separated_propers, "separated_propers", null, rx); } if (dbgAptr.isUseable()) { dbgAptr.appentln(" - Propers: " + Arrays.toString(propers)); } String[] overrides = null; try { if (separated_overrides.length() == 0) { overrides = EMPTY_STRING_ARRAY; } else { overrides = separated_overrides.split(separator); } } catch (RuntimeException rx) { throw CrashIfObject.nullOrReturnCause(separated_overrides, "separated_overrides", null, rx); } if (dbgAptr.isUseable()) { dbgAptr.appentln(" - Overrides: " + Arrays.toString(overrides) + "...DONE"); } return new FilenameBlackWhiteList(bw, ioc, propers, overrides, dbgAccept_ifNonNull); }
From source file:jenkins.scm.impl.subversion.SubversionSCMSource.java
/** * Checks if we have a match against a wildcard matcher. * * @param value the value//from ww w. j a va 2 s . c o m * @param wildcareMatcher the wildcard matcher * @return {@code true} if and only if the value matches the wildcard matcher. */ static boolean isMatch(@NonNull String value, @NonNull String wildcareMatcher) { return FilenameUtils.wildcardMatch(value, wildcareMatcher, IOCase.SENSITIVE); }
From source file:com.matteoveroni.model.copy.FilenameUtils.java
/** * Checks whether two filenames are equal exactly. * <p>//from w w w . j av a 2s . co m * No processing is performed on the filenames other than comparison, * thus this is merely a null-safe case-sensitive equals. * * @param filename1 the first filename to query, may be null * @param filename2 the second filename to query, may be null * @return true if the filenames are equal, null equals null * @see IOCase#SENSITIVE */ public static boolean equals(String filename1, String filename2) { return equals(filename1, filename2, false, IOCase.SENSITIVE); }
From source file:com.matteoveroni.model.copy.FilenameUtils.java
/** * Checks whether two filenames are equal after both have been normalized. * <p>/*w w w. ja v a2s . c o m*/ * Both filenames are first passed to {@link #normalize(String)}. * The check is then performed in a case-sensitive manner. * * @param filename1 the first filename to query, may be null * @param filename2 the second filename to query, may be null * @return true if the filenames are equal, null equals null * @see IOCase#SENSITIVE */ public static boolean equalsNormalized(String filename1, String filename2) { return equals(filename1, filename2, true, IOCase.SENSITIVE); }
From source file:com.matteoveroni.model.copy.FilenameUtils.java
/** * Checks whether two filenames are equal, optionally normalizing and providing * control over the case-sensitivity.//from w ww . j a v a 2 s. c om * * @param filename1 the first filename to query, may be null * @param filename2 the second filename to query, may be null * @param normalized whether to normalize the filenames * @param caseSensitivity what case sensitivity rule to use, null means case-sensitive * @return true if the filenames are equal, null equals null * @since 1.3 */ public static boolean equals(String filename1, String filename2, boolean normalized, IOCase caseSensitivity) { if (filename1 == null || filename2 == null) { return filename1 == null && filename2 == null; } if (normalized) { filename1 = normalize(filename1); filename2 = normalize(filename2); if (filename1 == null || filename2 == null) { throw new NullPointerException("Error normalizing one or both of the file names"); } } if (caseSensitivity == null) { caseSensitivity = IOCase.SENSITIVE; } return caseSensitivity.checkEquals(filename1, filename2); }
From source file:com.matteoveroni.model.copy.FilenameUtils.java
/** * Checks a filename to see if it matches the specified wildcard matcher, * always testing case-sensitive.// w w w . j a v a2 s . c om * <p> * The wildcard matcher uses the characters '?' and '*' to represent a * single or multiple (zero or more) wildcard characters. * This is the same as often found on Dos/Unix command lines. * The check is case-sensitive always. * <pre> * wildcardMatch("c.txt", "*.txt") --> true * wildcardMatch("c.txt", "*.jpg") --> false * wildcardMatch("a/b/c.txt", "a/b/*") --> true * wildcardMatch("c.txt", "*.???") --> true * wildcardMatch("c.txt", "*.????") --> false * </pre> * N.B. the sequence "*?" does not work properly at present in match strings. * * @param filename the filename to match on * @param wildcardMatcher the wildcard string to match against * @return true if the filename matches the wilcard string * @see IOCase#SENSITIVE */ public static boolean wildcardMatch(String filename, String wildcardMatcher) { return wildcardMatch(filename, wildcardMatcher, IOCase.SENSITIVE); }