org.apache.commons.io.FilenameUtils.wildcardMatch()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(14.5k)|赞(0)|评价(0)|浏览(238)

本文整理了Java中org.apache.commons.io.FilenameUtils.wildcardMatch()方法的一些代码示例,展示了FilenameUtils.wildcardMatch()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FilenameUtils.wildcardMatch()方法的具体详情如下:
包路径:org.apache.commons.io.FilenameUtils
类名称:FilenameUtils
方法名:wildcardMatch

FilenameUtils.wildcardMatch介绍

[英]Checks a filename to see if it matches the specified wildcard matcher, always testing case-sensitive.

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.

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

N.B. the sequence "?" does not work properly at present in match strings.
[中]检查文件名是否与指定的通配符匹配,始终测试区分大小写。
通配符匹配器使用字符“?”和“
”表示一个或多个(零个或多个)通配符。这与通常在Dos/Unix命令行中找到的相同。支票始终区分大小写。

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

注意顺序“*?”目前无法在匹配字符串中正常工作。

代码示例

代码示例来源:origin: commons-io/commons-io

@Override
  public boolean matches(final String className) {
    return FilenameUtils.wildcardMatch(className, pattern);
  }
}

代码示例来源:origin: commons-io/commons-io

/**
 * Checks to see if the filename matches one of the wildcards.
 *
 * @param dir  the file directory (ignored)
 * @param name  the filename
 * @return true if the filename matches one of the wildcards
 */
@Override
public boolean accept(final File dir, final String name) {
  for (final String wildcard : wildcards) {
    if (FilenameUtils.wildcardMatch(name, wildcard, caseSensitivity)) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: commons-io/commons-io

/**
 * Checks a filename to see if it matches the specified wildcard matcher
 * using the case rules of the system.
 * <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 on Unix and case-insensitive on Windows.
 * <pre>
 * wildcardMatch("c.txt", "*.txt")      --&gt; true
 * wildcardMatch("c.txt", "*.jpg")      --&gt; false
 * wildcardMatch("a/b/c.txt", "a/b/*")  --&gt; true
 * wildcardMatch("c.txt", "*.???")      --&gt; true
 * wildcardMatch("c.txt", "*.????")     --&gt; 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 wildcard string
 * @see IOCase#SYSTEM
 */
public static boolean wildcardMatchOnSystem(final String filename, final String wildcardMatcher) {
  return wildcardMatch(filename, wildcardMatcher, IOCase.SYSTEM);
}

代码示例来源:origin: commons-io/commons-io

/**
 * Checks a filename to see if it matches the specified wildcard matcher,
 * always testing case-sensitive.
 * <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")      --&gt; true
 * wildcardMatch("c.txt", "*.jpg")      --&gt; false
 * wildcardMatch("a/b/c.txt", "a/b/*")  --&gt; true
 * wildcardMatch("c.txt", "*.???")      --&gt; true
 * wildcardMatch("c.txt", "*.????")     --&gt; 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 wildcard string
 * @see IOCase#SENSITIVE
 */
public static boolean wildcardMatch(final String filename, final String wildcardMatcher) {
  return wildcardMatch(filename, wildcardMatcher, IOCase.SENSITIVE);
}

代码示例来源:origin: commons-io/commons-io

/**
 * Checks to see if the filename matches one of the wildcards.
 *
 * @param file  the file to check
 * @return true if the filename matches one of the wildcards
 */
@Override
public boolean accept(final File file) {
  final String name = file.getName();
  for (final String wildcard : wildcards) {
    if (FilenameUtils.wildcardMatch(name, wildcard, caseSensitivity)) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: org.apache.commons/commons-io

/**
 * Checks to see if the filename matches one of the wildcards.
 *
 * @param dir  the file directory
 * @param name  the filename
 * @return true if the filename matches one of the wildcards
 */
public boolean accept(File dir, String name) {
  for (int i = 0; i < wildcards.length; i++) {
    if (FilenameUtils.wildcardMatch(name, wildcards[i], caseSensitivity)) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: commons-io/commons-io

/**
 * Checks to see if the filename matches one of the wildcards.
 *
 * @param file the file to check
 * @return true if the filename matches one of the wildcards
 */
@Override
public boolean accept(final File file) {
  if (file.isDirectory()) {
    return false;
  }
  for (final String wildcard : wildcards) {
    if (FilenameUtils.wildcardMatch(file.getName(), wildcard)) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: commons-io/commons-io

/**
 * Checks to see if the filename matches one of the wildcards.
 *
 * @param dir  the file directory
 * @param name  the filename
 * @return true if the filename matches one of the wildcards
 */
@Override
public boolean accept(final File dir, final String name) {
  if (dir != null && new File(dir, name).isDirectory()) {
    return false;
  }
  for (final String wildcard : wildcards) {
    if (FilenameUtils.wildcardMatch(name, wildcard)) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: org.apache.commons/commons-io

/**
 * Checks a filename to see if it matches the specified wildcard matcher
 * using the case rules of the system.
 * <p>
 * The wildcard matcher uses the characters '?' and '*' to represent a
 * single or multiple wildcard characters.
 * This is the same as often found on Dos/Unix command lines.
 * The check is case-sensitive on Unix and case-insensitive on Windows.
 * <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>
 * 
 * @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#SYSTEM
 */
public static boolean wildcardMatchOnSystem(String filename, String wildcardMatcher) {
  return wildcardMatch(filename, wildcardMatcher, IOCase.SYSTEM);
}

代码示例来源:origin: org.apache.commons/commons-io

/**
 * Checks a filename to see if it matches the specified wildcard matcher,
 * always testing case-sensitive.
 * <p>
 * The wildcard matcher uses the characters '?' and '*' to represent a
 * single or multiple 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>
 * 
 * @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);
}

代码示例来源:origin: org.apache.commons/commons-io

/**
 * Checks to see if the filename matches one of the wildcards.
 *
 * @param file  the file to check
 * @return true if the filename matches one of the wildcards
 */
public boolean accept(File file) {
  String name = file.getName();
  for (int i = 0; i < wildcards.length; i++) {
    if (FilenameUtils.wildcardMatch(name, wildcards[i], caseSensitivity)) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: org.apache.commons/commons-io

/**
 * Checks to see if the filename matches one of the wildcards.
 *
 * @param dir  the file directory
 * @param name  the filename
 * @return true if the filename matches one of the wildcards
 */
public boolean accept(File dir, String name) {
  if (dir != null && new File(dir, name).isDirectory()) {
    return false;
  }
  
  for (int i = 0; i < wildcards.length; i++) {
    if (FilenameUtils.wildcardMatch(name, wildcards[i])) {
      return true;
    }
  }
  
  return false;
}

代码示例来源:origin: org.apache.commons/commons-io

/**
 * Checks to see if the filename matches one of the wildcards.
 *
 * @param file the file to check
 * @return true if the filename matches one of the wildcards
 */
public boolean accept(File file) {
  if (file.isDirectory()) {
    return false;
  }
  
  for (int i = 0; i < wildcards.length; i++) {
    if (FilenameUtils.wildcardMatch(file.getName(), wildcards[i])) {
      return true;
    }
  }
  
  return false;
}

代码示例来源:origin: commons-io/commons-io

private void assertMatch(final String text, final String wildcard, final boolean expected) {
  assertEquals(text + " " + wildcard, expected, FilenameUtils.wildcardMatch(text, wildcard));
}

代码示例来源:origin: apache/hbase

if (FilenameUtils.wildcardMatch(
  Path.getPathWithoutSchemeAndAuthority(coprocPath).toString(),
  Path.getPathWithoutSchemeAndAuthority(wlPath).toString())) {

代码示例来源:origin: commons-io/commons-io

@Test
public void testMatch() {
  assertFalse(FilenameUtils.wildcardMatch(null, "Foo"));
  assertFalse(FilenameUtils.wildcardMatch("Foo", null));
  assertTrue(FilenameUtils.wildcardMatch(null, null));
  assertTrue(FilenameUtils.wildcardMatch("Foo", "Foo"));
  assertTrue(FilenameUtils.wildcardMatch("", ""));
  assertTrue(FilenameUtils.wildcardMatch("", "*"));
  assertFalse(FilenameUtils.wildcardMatch("", "?"));
  assertTrue(FilenameUtils.wildcardMatch("Foo", "Fo*"));
  assertTrue(FilenameUtils.wildcardMatch("Foo", "Fo?"));
  assertTrue(FilenameUtils.wildcardMatch("Foo Bar and Catflap", "Fo*"));
  assertTrue(FilenameUtils.wildcardMatch("New Bookmarks", "N?w ?o?k??r?s"));
  assertFalse(FilenameUtils.wildcardMatch("Foo", "Bar"));
  assertTrue(FilenameUtils.wildcardMatch("Foo Bar Foo", "F*o Bar*"));
  assertTrue(FilenameUtils.wildcardMatch("Adobe Acrobat Installer", "Ad*er"));
  assertTrue(FilenameUtils.wildcardMatch("Foo", "*Foo"));
  assertTrue(FilenameUtils.wildcardMatch("BarFoo", "*Foo"));
  assertTrue(FilenameUtils.wildcardMatch("Foo", "Foo*"));
  assertTrue(FilenameUtils.wildcardMatch("FooBar", "Foo*"));
  assertFalse(FilenameUtils.wildcardMatch("FOO", "*Foo"));
  assertFalse(FilenameUtils.wildcardMatch("BARFOO", "*Foo"));
  assertFalse(FilenameUtils.wildcardMatch("FOO", "Foo*"));
  assertFalse(FilenameUtils.wildcardMatch("FOOBAR", "Foo*"));
}

代码示例来源:origin: commons-io/commons-io

@Test
public void testMatchCaseSpecified() {
  assertFalse(FilenameUtils.wildcardMatch(null, "Foo", IOCase.SENSITIVE));
  assertFalse(FilenameUtils.wildcardMatch("Foo", null, IOCase.SENSITIVE));
  assertTrue(FilenameUtils.wildcardMatch(null, null, IOCase.SENSITIVE));
  assertTrue(FilenameUtils.wildcardMatch("Foo", "Foo", IOCase.SENSITIVE));
  assertTrue(FilenameUtils.wildcardMatch("", "", IOCase.SENSITIVE));
  assertTrue(FilenameUtils.wildcardMatch("Foo", "Fo*", IOCase.SENSITIVE));
  assertTrue(FilenameUtils.wildcardMatch("Foo", "Fo?", IOCase.SENSITIVE));
  assertTrue(FilenameUtils.wildcardMatch("Foo Bar and Catflap", "Fo*", IOCase.SENSITIVE));
  assertTrue(FilenameUtils.wildcardMatch("New Bookmarks", "N?w ?o?k??r?s", IOCase.SENSITIVE));
  assertFalse(FilenameUtils.wildcardMatch("Foo", "Bar", IOCase.SENSITIVE));
  assertTrue(FilenameUtils.wildcardMatch("Foo Bar Foo", "F*o Bar*", IOCase.SENSITIVE));
  assertTrue(FilenameUtils.wildcardMatch("Adobe Acrobat Installer", "Ad*er", IOCase.SENSITIVE));
  assertTrue(FilenameUtils.wildcardMatch("Foo", "*Foo", IOCase.SENSITIVE));
  assertTrue(FilenameUtils.wildcardMatch("Foo", "Foo*", IOCase.SENSITIVE));
  assertTrue(FilenameUtils.wildcardMatch("Foo", "*Foo", IOCase.SENSITIVE));
  assertTrue(FilenameUtils.wildcardMatch("BarFoo", "*Foo", IOCase.SENSITIVE));
  assertTrue(FilenameUtils.wildcardMatch("Foo", "Foo*", IOCase.SENSITIVE));
  assertTrue(FilenameUtils.wildcardMatch("FooBar", "Foo*", IOCase.SENSITIVE));
  assertFalse(FilenameUtils.wildcardMatch("FOO", "*Foo", IOCase.SENSITIVE));
  assertFalse(FilenameUtils.wildcardMatch("BARFOO", "*Foo", IOCase.SENSITIVE));
  assertFalse(FilenameUtils.wildcardMatch("FOO", "Foo*", IOCase.SENSITIVE));
  assertFalse(FilenameUtils.wildcardMatch("FOOBAR", "Foo*", IOCase.SENSITIVE));
  assertTrue(FilenameUtils.wildcardMatch("FOO", "*Foo", IOCase.INSENSITIVE));
  assertTrue(FilenameUtils.wildcardMatch("BARFOO", "*Foo", IOCase.INSENSITIVE));
  assertTrue(FilenameUtils.wildcardMatch("FOO", "Foo*", IOCase.INSENSITIVE));
  assertTrue(FilenameUtils.wildcardMatch("FOOBAR", "Foo*", IOCase.INSENSITIVE));
  assertEquals(WINDOWS, FilenameUtils.wildcardMatch("FOO", "*Foo", IOCase.SYSTEM));

代码示例来源:origin: commons-io/commons-io

@Test
public void testLocaleIndependence() {
  final Locale orig = Locale.getDefault();
  final Locale[] locales = Locale.getAvailableLocales();
  final String[][] data = {
    { "I", "i"},
    { "i", "I"},
    { "i", "\u0130"},
    { "i", "\u0131"},
    { "\u03A3", "\u03C2"},
    { "\u03A3", "\u03C3"},
    { "\u03C2", "\u03C3"},
  };
  try {
    for (int i = 0; i < data.length; i++) {
      for (final Locale locale : locales) {
        Locale.setDefault(locale);
        assertTrue("Test data corrupt: " + i, data[i][0].equalsIgnoreCase(data[i][1]));
        final boolean match = FilenameUtils.wildcardMatch(data[i][0], data[i][1], IOCase.INSENSITIVE);
        assertTrue(Locale.getDefault().toString() + ": " + i, match);
      }
    }
  } finally {
    Locale.setDefault(orig);
  }
}

代码示例来源:origin: primefaces/primefaces

if (FilenameUtils.wildcardMatch(contentType.toLowerCase(), accept)) {
  accepted = true;
  if (LOGGER.isLoggable(Level.FINE)) {

代码示例来源:origin: torakiki/pdfsam

/**
   * @param filename
   * @return true if the input filename is of this {@link FileType}
   */
  public boolean matches(String filename) {
    for (String current : getFilter().getExtensions()) {
      if (wildcardMatch(filename, current, IOCase.INSENSITIVE)) {
        return true;
      }
    }
    return false;
  }
}

相关文章