public class ExtensionFileFilter extends FileFilter implements FileFilter, FilenameFilter
FileFilter
and implements
both the Java I/O interfaces FileFilter
and FilenameFilter
. It implements functionality similar
to that of FileNameExtensionFilter
but offers more features and allows extending this class, which is
prohibited by FileNameExtensionFilter
.Modifier and Type | Field and Description |
---|---|
static char |
EXTENSION_SEPARATOR
The character separating an extension from the file name.
|
Constructor and Description |
---|
ExtensionFileFilter(String description,
boolean addExtensionListToDescription,
List<String> extensions)
Creates a new instance of this class.
|
ExtensionFileFilter(String description,
boolean addExtensionListToDescription,
String... extensions)
Creates a new instance of this class.
|
Modifier and Type | Method and Description |
---|---|
boolean |
accept(File f)
This default implementation accepts all files that are directories or that end with one of the defined extensions.
|
boolean |
accept(File dir,
String name)
|
String |
getDefaultExtension()
Returns the default file extension of this filter.
|
String |
getDescription() |
List<String> |
getExtensions()
Returns a list of all extensions accepted by this filter.
|
String |
getExtensionsAsString()
Returns all extensions stored in this filter as a single string.
|
public static final char EXTENSION_SEPARATOR
public ExtensionFileFilter(String description, boolean addExtensionListToDescription, String... extensions)
description
- the description of this file type to be displayed e.g. in open dialogsaddExtensionListToDescription
- Specify true
here, if a list of valid extensions shall be appended
on the specified description in parentheses.extensions
- one and possibly additional alternative extensions accepted by this filter (All file extension
should be specified without a leading '.'
.)NullPointerException
- if description
or any specified extension are null
IllegalArgumentException
- if not at least one extension has been specifiedpublic ExtensionFileFilter(String description, boolean addExtensionListToDescription, List<String> extensions)
description
- the description of this file type to be displayed e.g. in open dialogsaddExtensionListToDescription
- Specify true
here, if a list of valid extensions shall be appended
on the specified description in parentheses.extensions
- one and possibly additional alternative extensions accepted by this filter (All file extension
should be specified without a leading '.'
.)NullPointerException
- if description
or any specified extension are null
IllegalArgumentException
- if not at least one extension has been specifiedpublic String getExtensionsAsString()
Example: If the extensions jpeg
, jpg
and jpe
would be have been passed to the constructor
of this class, the return value would be "*.jpeg;*.jpg;*.jpe
" (The path separator used, would depending on the
operating system).
public boolean accept(File f)
Inherited classes may add additional functionality to this method by overwriting, if the specified file extensions are ambiguous.
accept
in interface FileFilter
accept
in class FileFilter
FileFilter.accept(java.io.File)
,
FileFilter.accept(File)
public boolean accept(File dir, String name)
accept
in interface FilenameFilter
FilenameFilter.accept(java.io.File, java.lang.String)
public String getDescription()
getDescription
in class FileFilter
public String getDefaultExtension()
'.'
public List<String> getExtensions()
getDefaultExtension()
.