public abstract class ContentExtensionFileFilter extends ExtensionFileFilter
getTestStrategy()
and can be changed during runtime.Modifier and Type | Class and Description |
---|---|
static class |
ContentExtensionFileFilter.TestStrategy
Determines the way instances of
ContentExtensionFileFilter determine which files are valid. |
EXTENSION_SEPARATOR
Constructor and Description |
---|
ContentExtensionFileFilter(java.lang.String description,
boolean addExtensionListToDescription,
ContentExtensionFileFilter.TestStrategy testStrategy,
boolean acceptFilesWithExceptions,
java.lang.String... extensions)
Creates a new instance of this class.
|
ContentExtensionFileFilter(java.lang.String description,
boolean addExtensionListToDescription,
java.lang.String... extensions)
Creates a new instance of this class.
|
Modifier and Type | Method and Description |
---|---|
boolean |
accept(java.io.File f)
This default implementation accepts all files that are directories or that end with one of the defined extensions.
|
protected boolean |
acceptContent(java.io.File file)
Tests the contents of the specified file.
|
protected abstract boolean |
acceptContent(java.io.FileInputStream stream)
Inherited classes must implement this method to test the content of a file.
|
ContentExtensionFileFilter.TestStrategy |
getTestStrategy()
The strategy that is currently used to determine whether a file shall be accepted by this filter or not.
|
boolean |
isAcceptFilesWithExceptions()
Determines whether this filter accepts files where
IOException s were thrown while they were tested
with acceptContent(File) . |
void |
setAcceptFilesWithExceptions(boolean acceptFilesWithExceptions)
Specifies whether this filter accepts files where
IOException s were thrown while they were tested
with acceptContent(File) . |
void |
setTestStrategy(ContentExtensionFileFilter.TestStrategy testStrategy)
Specifies a new test strategy to determine whether a file shall be accepted by this filter or not.
|
accept, getDefaultExtension, getDescription, getExtensions, getExtensionsAsString
public ContentExtensionFileFilter(java.lang.String description, boolean addExtensionListToDescription, ContentExtensionFileFilter.TestStrategy testStrategy, boolean acceptFilesWithExceptions, java.lang.String... extensions)
All file extension parameters should be specified without a leading '.'
.
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.testStrategy
- the strategy to be used to accept a file or notacceptFilesWithExceptions
- Specify true
here, if files where IOException
s are thrown while
they were tested should be accepted in acceptContent(File)
or false
otherwise.extensions
- one and possibly additional alternative extensions accepted by this filter (All file extension
should be specified without a leading '.'
.)java.lang.NullPointerException
- if description
or any specified extension are null
java.lang.IllegalArgumentException
- if not at least one extension has been specifiedpublic ContentExtensionFileFilter(java.lang.String description, boolean addExtensionListToDescription, java.lang.String... extensions)
All file extension parameters should be specified without a leading '.'
.
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 '.'
.)java.lang.NullPointerException
- if description
or any specified extension are null
java.lang.IllegalArgumentException
- if not at least one extension has been specifiedpublic ContentExtensionFileFilter.TestStrategy getTestStrategy()
public void setTestStrategy(ContentExtensionFileFilter.TestStrategy testStrategy) throws java.lang.NullPointerException
testStrategy
- the test strategy to be used from now onjava.lang.NullPointerException
- if null
is provided as the new test strategypublic boolean isAcceptFilesWithExceptions()
IOException
s were thrown while they were tested
with acceptContent(File)
.true
if such files shall be accepted or false
otherwisepublic void setAcceptFilesWithExceptions(boolean acceptFilesWithExceptions)
IOException
s were thrown while they were tested
with acceptContent(File)
.acceptFilesWithExceptions
- Specify true
here, if such files shall be accepted or false
otherwiseprotected boolean acceptContent(java.io.File file)
#acceptContent(BufferedInputStream)
internally, if the specified
file is not a directory.
Inherited classes can overwrite this method, if additional checks shall be performed on the file. In some cases it may be useful to check in here, if the file extension is unique or not before calling
file
- the file to be testedtrue
if the specified file is accepted or false
otherwiseprotected abstract boolean acceptContent(java.io.FileInputStream stream) throws java.lang.Exception
BufferedInputStream
way significantly speed up testing, which may be relevant in folders containing
many files or folders on slow (network) resources.stream
- the input stream providing the content of the file to be testedtrue
if the specified content is accepted or false
otherwisejava.lang.Exception
public boolean accept(java.io.File f)
ExtensionFileFilter
Inherited classes may add additional functionality to this method by overwriting, if the specified file extensions are ambiguous.
accept
in interface java.io.FileFilter
accept
in class ExtensionFileFilter
FileFilter.accept(java.io.File)
,
FileFilter.accept(File)