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.
45 lines
773 B
45 lines
773 B
10 years ago
|
package mightypork.gamecore.util.files;
|
||
10 years ago
|
|
||
10 years ago
|
|
||
10 years ago
|
import java.io.File;
|
||
|
import java.io.FileFilter;
|
||
|
|
||
|
|
||
|
/**
|
||
|
* File filter for certain suffixes
|
||
|
*
|
||
|
* @author MightyPork
|
||
|
*/
|
||
|
public class FileSuffixFilter implements FileFilter {
|
||
10 years ago
|
|
||
10 years ago
|
/** Array of allowed suffixes */
|
||
|
private String[] suffixes = null;
|
||
10 years ago
|
|
||
|
|
||
10 years ago
|
/**
|
||
|
* Suffix filter
|
||
|
*
|
||
10 years ago
|
* @param suffixes var-args allowed suffixes, case insensitive
|
||
10 years ago
|
*/
|
||
10 years ago
|
public FileSuffixFilter(String... suffixes)
|
||
|
{
|
||
10 years ago
|
this.suffixes = suffixes;
|
||
|
}
|
||
10 years ago
|
|
||
|
|
||
10 years ago
|
@Override
|
||
|
public boolean accept(File pathname)
|
||
|
{
|
||
|
if (!pathname.isFile()) return false;
|
||
10 years ago
|
|
||
10 years ago
|
final String fname = pathname.getName().toLowerCase().trim();
|
||
10 years ago
|
|
||
10 years ago
|
for (final String suffix : suffixes) {
|
||
10 years ago
|
if (fname.endsWith(suffix.toLowerCase().trim())) { return true; }
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
return false;
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
}
|