Package org.apache.commons.io.filefilter
Class AbstractFileFilter
- java.lang.Object
-
- org.apache.commons.io.filefilter.AbstractFileFilter
-
- All Implemented Interfaces:
java.io.FileFilter
,java.io.FilenameFilter
,java.nio.file.FileVisitor<java.nio.file.Path>
,PathFilter
,PathVisitor
,IOFileFilter
- Direct Known Subclasses:
AgeFileFilter
,AndFileFilter
,CanExecuteFileFilter
,CanReadFileFilter
,CanWriteFileFilter
,DelegateFileFilter
,DirectoryFileFilter
,EmptyFileFilter
,FileEqualsFileFilter
,FileFileFilter
,HiddenFileFilter
,MagicNumberFileFilter
,NameFileFilter
,NotFileFilter
,OrFileFilter
,PathEqualsFileFilter
,PathVisitorFileFilter
,PrefixFileFilter
,RegexFileFilter
,SizeFileFilter
,SuffixFileFilter
,SymbolicLinkFileFilter
,WildcardFileFilter
,WildcardFilter
public abstract class AbstractFileFilter extends java.lang.Object implements IOFileFilter, PathVisitor
Abstracts the implementation of theFileFilter
(IO),FilenameFilter
(IO),PathFilter
(NIO) interfaces via our ownIOFileFilter
interface.Note that a subclass MUST override one of the
accept
methods, otherwise that subclass will infinitely loop.- Since:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description private java.nio.file.FileVisitResult
onAccept
What to do when this filter accepts.private java.nio.file.FileVisitResult
onReject
What to do when this filter rejects.-
Fields inherited from interface org.apache.commons.io.filefilter.IOFileFilter
EMPTY_STRING_ARRAY
-
-
Constructor Summary
Constructors Modifier Constructor Description AbstractFileFilter()
Constructs a new instance.protected
AbstractFileFilter(java.nio.file.FileVisitResult onAccept, java.nio.file.FileVisitResult onReject)
Constructs a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
accept(java.io.File file)
Checks to see if the File should be accepted by this filter.boolean
accept(java.io.File dir, java.lang.String name)
Checks to see if the File should be accepted by this filter.(package private) void
append(java.lang.Object[] array, java.lang.StringBuilder buffer)
(package private) void
append(java.util.List<?> list, java.lang.StringBuilder buffer)
(package private) java.nio.file.FileVisitResult
get(IOSupplier<java.nio.file.FileVisitResult> supplier)
protected java.nio.file.FileVisitResult
handle(java.lang.Throwable t)
Handles exceptions caught while accepting.java.nio.file.FileVisitResult
postVisitDirectory(java.nio.file.Path dir, java.io.IOException exc)
java.nio.file.FileVisitResult
preVisitDirectory(java.nio.file.Path dir, java.nio.file.attribute.BasicFileAttributes attributes)
(package private) static java.nio.file.FileVisitResult
toDefaultFileVisitResult(boolean accept)
(package private) java.nio.file.FileVisitResult
toFileVisitResult(boolean accept)
Converts a boolean into a FileVisitResult.java.lang.String
toString()
Provides a String representation of this file filter.java.nio.file.FileVisitResult
visitFile(java.nio.file.Path file, java.nio.file.attribute.BasicFileAttributes attributes)
java.nio.file.FileVisitResult
visitFileFailed(java.nio.file.Path file, java.io.IOException exc)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.commons.io.filefilter.IOFileFilter
accept, and, negate, or
-
-
-
-
Constructor Detail
-
AbstractFileFilter
public AbstractFileFilter()
Constructs a new instance.
-
AbstractFileFilter
protected AbstractFileFilter(java.nio.file.FileVisitResult onAccept, java.nio.file.FileVisitResult onReject)
Constructs a new instance.- Parameters:
onAccept
- What to do on acceptance.onReject
- What to do on rejection.- Since:
- 2.12.0.
-
-
Method Detail
-
toDefaultFileVisitResult
static java.nio.file.FileVisitResult toDefaultFileVisitResult(boolean accept)
-
accept
public boolean accept(java.io.File file)
Checks to see if the File should be accepted by this filter.- Specified by:
accept
in interfacejava.io.FileFilter
- Specified by:
accept
in interfaceIOFileFilter
- Parameters:
file
- the File to check- Returns:
- true if this file matches the test
-
accept
public boolean accept(java.io.File dir, java.lang.String name)
Checks to see if the File should be accepted by this filter.- Specified by:
accept
in interfacejava.io.FilenameFilter
- Specified by:
accept
in interfaceIOFileFilter
- Parameters:
dir
- the directory File to checkname
- the file name within the directory to check- Returns:
- true if this file matches the test
-
append
void append(java.util.List<?> list, java.lang.StringBuilder buffer)
-
append
void append(java.lang.Object[] array, java.lang.StringBuilder buffer)
-
get
java.nio.file.FileVisitResult get(IOSupplier<java.nio.file.FileVisitResult> supplier)
-
handle
protected java.nio.file.FileVisitResult handle(java.lang.Throwable t)
Handles exceptions caught while accepting.- Parameters:
t
- the caught Throwable.- Returns:
- the given Throwable.
- Since:
- 2.9.0
-
postVisitDirectory
public java.nio.file.FileVisitResult postVisitDirectory(java.nio.file.Path dir, java.io.IOException exc) throws java.io.IOException
- Specified by:
postVisitDirectory
in interfacejava.nio.file.FileVisitor<java.nio.file.Path>
- Throws:
java.io.IOException
-
preVisitDirectory
public java.nio.file.FileVisitResult preVisitDirectory(java.nio.file.Path dir, java.nio.file.attribute.BasicFileAttributes attributes) throws java.io.IOException
- Specified by:
preVisitDirectory
in interfacejava.nio.file.FileVisitor<java.nio.file.Path>
- Throws:
java.io.IOException
-
toFileVisitResult
java.nio.file.FileVisitResult toFileVisitResult(boolean accept)
Converts a boolean into a FileVisitResult.- Parameters:
accept
- accepted or rejected.- Returns:
- a FileVisitResult.
-
toString
public java.lang.String toString()
Provides a String representation of this file filter.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a String representation
-
visitFile
public java.nio.file.FileVisitResult visitFile(java.nio.file.Path file, java.nio.file.attribute.BasicFileAttributes attributes) throws java.io.IOException
- Specified by:
visitFile
in interfacejava.nio.file.FileVisitor<java.nio.file.Path>
- Throws:
java.io.IOException
-
visitFileFailed
public java.nio.file.FileVisitResult visitFileFailed(java.nio.file.Path file, java.io.IOException exc) throws java.io.IOException
- Specified by:
visitFileFailed
in interfacejava.nio.file.FileVisitor<java.nio.file.Path>
- Throws:
java.io.IOException
-
-