/** * Checks to see if the filename matches. * * @param dir the File directory (ignored) * @param name the filename * @return true if the filename matches */ @Override public boolean accept(final File dir, final String name) { for (final String name2 : names) { if (caseSensitivity.checkEquals(name, name2)) { return true; } } return false; }
/** * Compare the names of two files with the specified case sensitivity. * * @param file1 The first file to compare * @param file2 The second file to compare * @return a negative value if the first file's name * is less than the second, zero if the names are the * same and a positive value if the first files name * is greater than the second file. */ @Override public int compare(final File file1, final File file2) { return caseSensitivity.checkCompareTo(file1.getName(), file2.getName()); }
/** * Checks to see if the filename starts with the prefix. * * @param file the File directory * @param name the filename * @return true if the filename starts with one of our prefixes */ @Override public boolean accept(final File file, final String name) { for (final String prefix : prefixes) { if (caseSensitivity.checkStartsWith(name, prefix)) { return true; } } return false; }
/** * Factory method to create an IOCase from a name. * * @param name the name to find * @return the IOCase object * @throws IllegalArgumentException if the name is invalid */ public static IOCase forName(final String name) { for (final IOCase ioCase : IOCase.values()) { if (ioCase.getName().equals(name)) { return ioCase; } } throw new IllegalArgumentException("Invalid IOCase name: " + name); }
if (IOCase.SYSTEM.checkEquals(canonicalParent, canonicalChild)) { return false; return IOCase.SYSTEM.checkStartsWith(canonicalChild, canonicalParent);
textIdx = caseSensitivity.checkIndexOf(filename, textIdx, wcs[wcsIdx]); if (textIdx == NOT_FOUND) { final int repeat = caseSensitivity.checkIndexOf(filename, textIdx + 1, wcs[wcsIdx]); if (repeat >= 0) { backtrack.push(new int[] {wcsIdx, repeat}); if (!caseSensitivity.checkRegionMatches(filename, textIdx, wcs[wcsIdx])) {
/** * Construct a new regular expression filter with the specified flags case sensitivity. * * @param pattern regular string expression to match * @param caseSensitivity how to handle case sensitivity, null means case-sensitive * @throws IllegalArgumentException if the pattern is null */ public RegexFileFilter(final String pattern, final IOCase caseSensitivity) { if (pattern == null) { throw new IllegalArgumentException("Pattern is missing"); } int flags = 0; if (caseSensitivity != null && !caseSensitivity.isCaseSensitive()) { flags = Pattern.CASE_INSENSITIVE; } this.pattern = Pattern.compile(pattern, flags); }
/** * Replaces the enumeration from the stream with a real one. * This ensures that the correct flag is set for SYSTEM. * * @return the resolved object */ private Object readResolve() { return forName(name); }
/** * Checks to see if the filename ends with the suffix. * * @param file the File directory * @param name the filename * @return true if the filename ends with one of our suffixes */ @Override public boolean accept(final File file, final String name) { for (final String suffix : this.suffixes) { if (caseSensitivity.checkEndsWith(name, suffix)) { return true; } } return false; }
/** * Checks if one string contains another starting at a specific index using the * case-sensitivity rule. * <p> * This method mimics parts of {@link String#indexOf(String, int)} * but takes case-sensitivity into account. * * @param str the string to check, not null * @param strStartIndex the index to start at in str * @param search the start to search for, not null * @return the first index of the search String, * -1 if no match or {@code null} string input * @throws NullPointerException if either string is null * @since 2.0 */ public int checkIndexOf(final String str, final int strStartIndex, final String search) { final int endIndex = str.length() - search.length(); if (endIndex >= strStartIndex) { for (int i = strStartIndex; i <= endIndex; i++) { if (checkRegionMatches(str, i, search)) { return i; } } } return -1; }
@Test public void test_checkIndexOf_case() throws Exception { assertEquals(1, IOCase.SENSITIVE.checkIndexOf("ABC", 0, "BC")); assertEquals(-1, IOCase.SENSITIVE.checkIndexOf("ABC", 0, "Bc")); assertEquals(1, IOCase.INSENSITIVE.checkIndexOf("ABC", 0, "BC")); assertEquals(1, IOCase.INSENSITIVE.checkIndexOf("ABC", 0, "Bc")); assertEquals(1, IOCase.SYSTEM.checkIndexOf("ABC", 0, "BC")); assertEquals(WINDOWS ? 1 : -1, IOCase.SYSTEM.checkIndexOf("ABC", 0, "Bc")); }
textIdx = caseSensitivity.checkIndexOf(filename, textIdx, wcs[wcsIdx]); if (textIdx == -1) { int repeat = caseSensitivity.checkIndexOf(filename, textIdx + 1, wcs[wcsIdx]); if (repeat >= 0) { backtrack.push(new int[] {wcsIdx, repeat}); if (!caseSensitivity.checkRegionMatches(filename, textIdx, wcs[wcsIdx])) {
public static boolean isCaseSensitiveFS(File testDir) { if (testDir != null) { File caseCheckUpper = new File(testDir, "CaseCheck"); File caseCheckLow = new File(testDir, "casecheck"); try { makeDirs(testDir); if (caseCheckUpper.createNewFile()) { boolean caseSensitive = !caseCheckLow.exists(); LOG.debug("Filesystem at {} is {}case-sensitive", testDir.getAbsolutePath(), (caseSensitive ? "" : "NOT ")); return caseSensitive; } else { LOG.debug("Failed to create file: {}", caseCheckUpper.getAbsolutePath()); } } catch (Exception e) { LOG.debug("Failed to detect filesystem case-sensitivity by file creation", e); } finally { try { Files.deleteIfExists(caseCheckUpper.toPath()); Files.deleteIfExists(caseCheckLow.toPath()); } catch (Exception e) { // ignore } } } return IOCase.SYSTEM.isCaseSensitive(); }
/** * Replaces the enumeration from the stream with a real one. * This ensures that the correct flag is set for SYSTEM. * * @return the resolved object */ private Object readResolve() { return forName(name); }
/** * Checks to see if the filename ends with the suffix. * * @param file the File to check * @return true if the filename ends with one of our suffixes */ @Override public boolean accept(final File file) { final String name = file.getName(); for (final String suffix : this.suffixes) { if (caseSensitivity.checkEndsWith(name, suffix)) { return true; } } return false; }
@Test public void test_checkRegionMatches_case() throws Exception { assertTrue(IOCase.SENSITIVE.checkRegionMatches("ABC", 0, "AB")); assertFalse(IOCase.SENSITIVE.checkRegionMatches("ABC", 0, "Ab")); assertTrue(IOCase.INSENSITIVE.checkRegionMatches("ABC", 0, "AB")); assertTrue(IOCase.INSENSITIVE.checkRegionMatches("ABC", 0, "Ab")); assertTrue(IOCase.SYSTEM.checkRegionMatches("ABC", 0, "AB")); assertEquals(WINDOWS, IOCase.SYSTEM.checkRegionMatches("ABC", 0, "Ab")); }
assertEquals(0, IOCase.SENSITIVE.checkIndexOf("ABCDEFGHIJ", 0, "A")); assertEquals(-1, IOCase.SENSITIVE.checkIndexOf("ABCDEFGHIJ", 1, "A")); assertEquals(0, IOCase.SENSITIVE.checkIndexOf("ABCDEFGHIJ", 0, "AB")); assertEquals(-1, IOCase.SENSITIVE.checkIndexOf("ABCDEFGHIJ", 1, "AB")); assertEquals(0, IOCase.SENSITIVE.checkIndexOf("ABCDEFGHIJ", 0, "ABC")); assertEquals(-1, IOCase.SENSITIVE.checkIndexOf("ABCDEFGHIJ", 1, "ABC")); assertEquals(3, IOCase.SENSITIVE.checkIndexOf("ABCDEFGHIJ", 0, "D")); assertEquals(3, IOCase.SENSITIVE.checkIndexOf("ABCDEFGHIJ", 3, "D")); assertEquals(-1, IOCase.SENSITIVE.checkIndexOf("ABCDEFGHIJ", 4, "D")); assertEquals(3, IOCase.SENSITIVE.checkIndexOf("ABCDEFGHIJ", 0, "DE")); assertEquals(3, IOCase.SENSITIVE.checkIndexOf("ABCDEFGHIJ", 3, "DE")); assertEquals(-1, IOCase.SENSITIVE.checkIndexOf("ABCDEFGHIJ", 4, "DE")); assertEquals(3, IOCase.SENSITIVE.checkIndexOf("ABCDEFGHIJ", 0, "DEF")); assertEquals(3, IOCase.SENSITIVE.checkIndexOf("ABCDEFGHIJ", 3, "DEF")); assertEquals(-1, IOCase.SENSITIVE.checkIndexOf("ABCDEFGHIJ", 4, "DEF")); assertEquals(9, IOCase.SENSITIVE.checkIndexOf("ABCDEFGHIJ", 0, "J")); assertEquals(9, IOCase.SENSITIVE.checkIndexOf("ABCDEFGHIJ", 8, "J")); assertEquals(9, IOCase.SENSITIVE.checkIndexOf("ABCDEFGHIJ", 9, "J")); assertEquals(8, IOCase.SENSITIVE.checkIndexOf("ABCDEFGHIJ", 0, "IJ")); assertEquals(8, IOCase.SENSITIVE.checkIndexOf("ABCDEFGHIJ", 8, "IJ")); assertEquals(-1, IOCase.SENSITIVE.checkIndexOf("ABCDEFGHIJ", 9, "IJ")); assertEquals(7, IOCase.SENSITIVE.checkIndexOf("ABCDEFGHIJ", 6, "HIJ")); assertEquals(7, IOCase.SENSITIVE.checkIndexOf("ABCDEFGHIJ", 7, "HIJ")); assertEquals(-1, IOCase.SENSITIVE.checkIndexOf("ABCDEFGHIJ", 8, "HIJ")); assertEquals(-1, IOCase.SENSITIVE.checkIndexOf("ABCDEFGHIJ", 0, "DED"));
/** * Factory method to create an IOCase from a name. * * @param name the name to find * @return the IOCase object * @throws IllegalArgumentException if the name is invalid */ public static IOCase forName(final String name) { for (IOCase ioCase : IOCase.values()) { if (ioCase.getName().equals(name)) { return ioCase; } } throw new IllegalArgumentException("Invalid IOCase name: " + name); }
textIdx = caseSensitivity.checkIndexOf(filename, textIdx, wcs[wcsIdx]); if (textIdx == NOT_FOUND) { final int repeat = caseSensitivity.checkIndexOf(filename, textIdx + 1, wcs[wcsIdx]); if (repeat >= 0) { backtrack.push(new int[] {wcsIdx, repeat}); if (!caseSensitivity.checkRegionMatches(filename, textIdx, wcs[wcsIdx])) {