org.apache.commons.io.filefilter

## Class AbstractFileFilter

- java.lang.Object
- - org.apache.commons.io.filefilter.AbstractFileFilter

- All Implemented Interfaces:
    FileFilter, FilenameFilter, FileVisitor<Path>, PathMatcher, PathFilter, PathVisitor, IOFileFilter
  Direct Known Subclasses:
    AgeFileFilter, AndFileFilter, CanExecuteFileFilter, CanReadFileFilter, CanWriteFileFilter, DelegateFileFilter, DirectoryFileFilter, EmptyFileFilter, FileEqualsFileFilter, FileFileFilter, HiddenFileFilter, MagicNumberFileFilter, NameFileFilter, NotFileFilter, OrFileFilter, PathEqualsFileFilter, PathMatcherFileFilter, PathVisitorFileFilter, PrefixFileFilter, RegexFileFilter, SizeFileFilter, SuffixFileFilter, SymbolicLinkFileFilter, WildcardFileFilter

      public abstract class AbstractFileFilter
      extends Object
      implements IOFileFilter, PathVisitor

  Abstracts the implementation of the `FileFilter` (IO), `FilenameFilter` (IO), `PathFilter` (NIO) interfaces via our own `IOFileFilter` interface.

  Note that a subclass MUST override one of the `accept` methods, otherwise that subclass will infinitely loop.

- - ### Field Summary

    - ### Fields inherited from interface org.apache.commons.io.filefilter.IOFileFilter

      `EMPTY_STRING_ARRAY`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `` | `AbstractFileFilter()` Constructs a new instance.
    `protected` | `AbstractFileFilter(FileVisitResult onAccept, FileVisitResult onReject)` Constructs a new instance.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `accept(File file)` Tests to see if the File should be accepted by this filter.
    `boolean` | `accept(File dir, String name)` Tests to see if the File should be accepted by this filter.
    `(package private) void` | `append(List<?> list, StringBuilder buffer)` Append list to string builder.
    `(package private) void` | `append(Object[] array, StringBuilder buffer)` Append array to string builder.
    `(package private) FileVisitResult` | `get(IOSupplier<FileVisitResult> supplier)` Get file visit result from supplier.
    `protected FileVisitResult` | `handle(Throwable t)` Handles exceptions caught while accepting.
    `(package private) boolean` | `isDirectory(File file)` Check if file is a directory.
    `(package private) boolean` | `isFile(File file)` Check if file is a regular file.
    `FileVisitResult` | `postVisitDirectory(Path dir, IOException exc)`
    `FileVisitResult` | `preVisitDirectory(Path dir, BasicFileAttributes attributes)`
    `(package private) static FileVisitResult` | `toDefaultFileVisitResult(boolean accept)` Convert boolean to default file visit result.
    `(package private) FileVisitResult` | `toFileVisitResult(boolean accept)` Converts a boolean into a FileVisitResult.
    `String` | `toString()` Provides a String representation of this file filter.
    `FileVisitResult` | `visitFile(Path file, BasicFileAttributes attributes)`
    `FileVisitResult` | `visitFileFailed(Path file, 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, matches, negate, or`

- - ### Constructor Detail

    - #### AbstractFileFilter

          public AbstractFileFilter()

      Constructs a new instance.

    - #### AbstractFileFilter

          protected AbstractFileFilter(FileVisitResult onAccept,
                                       FileVisitResult onReject)

      Constructs a new instance.
      Parameters:
        `onAccept` - What to do on acceptance.
        `onReject` - What to do on rejection.

  - ### Method Detail

    - #### accept

          public boolean accept(File file)

      Tests to see if the File should be accepted by this filter.
      Specified by:
        `accept` in interface `FileFilter`
      Specified by:
        `accept` in interface `IOFileFilter`
      Parameters:
        `file` - the File to check
      Returns:
        true if this file matches the test

    - #### accept

          public boolean accept(File dir,
                                String name)

      Tests to see if the File should be accepted by this filter.
      Specified by:
        `accept` in interface `FilenameFilter`
      Specified by:
        `accept` in interface `IOFileFilter`
      Parameters:
        `dir` - the directory File to check
        `name` - the file name within the directory to check
      Returns:
        true if this file matches the test

    - #### append

          void append(List<?> list,
                      StringBuilder buffer)

      Append list to string builder.
      Parameters:
        `list` - the list to append
        `buffer` - the string builder to append to

    - #### append

          void append(Object[] array,
                      StringBuilder buffer)

      Append array to string builder.
      Parameters:
        `array` - the array to append
        `buffer` - the string builder to append to

    - #### get

          FileVisitResult get(IOSupplier<FileVisitResult> supplier)

      Get file visit result from supplier.
      Parameters:
        `supplier` - the supplier to get the result from
      Returns:
        the file visit result from the supplier, or TERMINATE if IOException occurs

    - #### handle

          protected FileVisitResult handle(Throwable t)

      Handles exceptions caught while accepting.
      Parameters:
        `t` - the caught Throwable.
      Returns:
        the given Throwable.

    - #### isDirectory

          boolean isDirectory(File file)

      Check if file is a directory.
      Parameters:
        `file` - the file to check
      Returns:
        true if the file is not null and is a directory

    - #### isFile

          boolean isFile(File file)

      Check if file is a regular file.
      Parameters:
        `file` - file to check
      Returns:
        true if the file is not null and is a regular file

    - #### postVisitDirectory

          public FileVisitResult postVisitDirectory(Path dir,
                                                    IOException exc)
                                             throws IOException

      Specified by:
        `postVisitDirectory` in interface `FileVisitor<Path>`
      Throws:
        `IOException`

    - #### preVisitDirectory

          public FileVisitResult preVisitDirectory(Path dir,
                                                   BasicFileAttributes attributes)
                                            throws IOException

      Specified by:
        `preVisitDirectory` in interface `FileVisitor<Path>`
      Throws:
        `IOException`

    - #### toDefaultFileVisitResult

          static FileVisitResult toDefaultFileVisitResult(boolean accept)

      Convert boolean to default file visit result.
      Parameters:
        `accept` - the boolean value to convert
      Returns:
        FileVisitResult.CONTINUE if accept is true, otherwise FileVisitResult.TERMINATE

    - #### toFileVisitResult

          FileVisitResult toFileVisitResult(boolean accept)

      Converts a boolean into a FileVisitResult.
      Parameters:
        `accept` - accepted or rejected.
      Returns:
        a FileVisitResult.

    - #### toString

          public String toString()

      Provides a String representation of this file filter.
      Overrides:
        `toString` in class `Object`
      Returns:
        a String representation

    - #### visitFile

          public FileVisitResult visitFile(Path file,
                                           BasicFileAttributes attributes)
                                    throws IOException

      Specified by:
        `visitFile` in interface `FileVisitor<Path>`
      Throws:
        `IOException`

    - #### visitFileFailed

          public FileVisitResult visitFileFailed(Path file,
                                                 IOException exc)
                                          throws IOException

      Specified by:
        `visitFileFailed` in interface `FileVisitor<Path>`
      Throws:
        `IOException`