You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
759 B
46 lines
759 B
10 years ago
|
package mightypork.utils.string.validation;
|
||
|
|
||
|
|
||
|
import java.io.File;
|
||
|
import java.io.FileFilter;
|
||
|
|
||
|
|
||
|
/**
|
||
|
* File filter for certain suffixes
|
||
|
*
|
||
|
* @author MightyPork
|
||
|
*/
|
||
|
public class FileSuffixFilter implements FileFilter {
|
||
|
|
||
|
/** Array of allowed suffixes */
|
||
|
private String[] suffixes = null;
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Suffix filter
|
||
|
*
|
||
|
* @param suffixes var-args allowed suffixes, case insensitive
|
||
|
*/
|
||
|
public FileSuffixFilter(String... suffixes) {
|
||
|
this.suffixes = suffixes;
|
||
|
}
|
||
|
|
||
|
|
||
|
@Override
|
||
|
public boolean accept(File pathname)
|
||
|
{
|
||
|
if (!pathname.isFile()) return false;
|
||
|
|
||
|
String fname = pathname.getName().toLowerCase().trim();
|
||
|
|
||
|
for (String suffix : suffixes) {
|
||
|
if (fname.endsWith(suffix.toLowerCase().trim())) {
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
}
|