org.apache.commons.io.file

## Class CountingPathVisitor

- java.lang.Object
- - java.nio.file.SimpleFileVisitor<Path>
  - - org.apache.commons.io.file.SimplePathVisitor
    - - org.apache.commons.io.file.CountingPathVisitor

- All Implemented Interfaces:
    FileVisitor<Path>, PathVisitor
  Direct Known Subclasses:
    AccumulatorPathVisitor, CleaningPathVisitor, CopyDirectoryVisitor, DeletingPathVisitor

      public class CountingPathVisitor
      extends SimplePathVisitor

  Counts files, directories, and sizes, as a visit proceeds.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `CountingPathVisitor.AbstractBuilder<T,B extends CountingPathVisitor.AbstractBuilder<T,B>>` Builds instances of `CountingPathVisitor`.
    `static class` | `CountingPathVisitor.Builder` Builds instances of `CountingPathVisitor`.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `(package private) static String[]` | `EMPTY_STRING_ARRAY`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CountingPathVisitor(Counters.PathCounters pathCounters)` Constructs a new instance.
    `CountingPathVisitor(Counters.PathCounters pathCounters, PathFilter fileFilter, PathFilter directoryFilter)` Constructs a new instance.
    `CountingPathVisitor(CountingPathVisitor.AbstractBuilder<?,?> builder)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected boolean` | `accept(Path file, BasicFileAttributes attributes)` Tests whether the given file is accepted by the file filter.
    `(package private) static IOFileFilter` | `defaultDirectoryFilter()`
    `(package private) static java.util.function.UnaryOperator<Path>` | `defaultDirectoryTransformer()`
    `(package private) static IOFileFilter` | `defaultFileFilter()`
    `(package private) static Counters.PathCounters` | `defaultPathCounters()`
    `boolean` | `equals(Object obj)`
    `Counters.PathCounters` | `getPathCounters()` Gets the visitation counts.
    `int` | `hashCode()`
    `FileVisitResult` | `postVisitDirectory(Path dir, IOException exc)`
    `FileVisitResult` | `preVisitDirectory(Path dir, BasicFileAttributes attributes)`
    `String` | `toString()`
    `protected void` | `updateDirCounter(Path dir, IOException exc)` Updates the counter for visiting the given directory.
    `protected void` | `updateFileCounters(Path file, BasicFileAttributes attributes)` Updates the counters for visiting the given file.
    `FileVisitResult` | `visitFile(Path file, BasicFileAttributes attributes)`
    `static CountingPathVisitor` | `withBigIntegerCounters()` Constructs a new instance configured with a `BigInteger` `Counters.PathCounters`.
    `static CountingPathVisitor` | `withLongCounters()` Constructs a new instance configured with a `long` `Counters.PathCounters`.

    - ### Methods inherited from class org.apache.commons.io.file.SimplePathVisitor

      `visitFileFailed`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### EMPTY_STRING_ARRAY

          static final String[] EMPTY_STRING_ARRAY

  - ### Constructor Detail

    - #### CountingPathVisitor

          public CountingPathVisitor(Counters.PathCounters pathCounters)

      Constructs a new instance.
      Parameters:
        `pathCounters` - How to count path visits.
      See Also:
        `CountingPathVisitor.Builder`

    - #### CountingPathVisitor

          public CountingPathVisitor(Counters.PathCounters pathCounters,
                                     PathFilter fileFilter,
                                     PathFilter directoryFilter)

      Constructs a new instance.
      Parameters:
        `pathCounters` - How to count path visits.
        `fileFilter` - Filters which files to count.
        `directoryFilter` - Filters which directories to count.
      See Also:
        `CountingPathVisitor.Builder`

    - #### CountingPathVisitor

          CountingPathVisitor(CountingPathVisitor.AbstractBuilder<?,?> builder)

  - ### Method Detail

    - #### accept

          protected boolean accept(Path file,
                                   BasicFileAttributes attributes)

      Tests whether the given file is accepted by the file filter.
      Parameters:
        `file` - the visited file.
        `attributes` - the visited file attributes.
      Returns:
        true to copy the given file, false if not.

    - #### defaultDirectoryFilter

          static IOFileFilter defaultDirectoryFilter()

    - #### defaultDirectoryTransformer

          static java.util.function.UnaryOperator<Path> defaultDirectoryTransformer()

    - #### defaultFileFilter

          static IOFileFilter defaultFileFilter()

    - #### defaultPathCounters

          static Counters.PathCounters defaultPathCounters()

    - #### equals

          public boolean equals(Object obj)

      Overrides:
        `equals` in class `Object`

    - #### getPathCounters

          public Counters.PathCounters getPathCounters()

      Gets the visitation counts.
      Returns:
        the visitation counts.

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### postVisitDirectory

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

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

    - #### preVisitDirectory

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

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

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### updateDirCounter

          protected void updateDirCounter(Path dir,
                                          IOException exc)

      Updates the counter for visiting the given directory.
      Parameters:
        `dir` - the visited directory.
        `exc` - Encountered exception.

    - #### updateFileCounters

          protected void updateFileCounters(Path file,
                                            BasicFileAttributes attributes)

      Updates the counters for visiting the given file.
      Parameters:
        `file` - the visited file.
        `attributes` - the visited file attributes.

    - #### visitFile

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

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

    - #### withBigIntegerCounters

          public static CountingPathVisitor withBigIntegerCounters()

      Constructs a new instance configured with a `BigInteger` `Counters.PathCounters`.
      Returns:
        a new instance configured with a `BigInteger` `Counters.PathCounters`.

    - #### withLongCounters

          public static CountingPathVisitor withLongCounters()

      Constructs a new instance configured with a `long` `Counters.PathCounters`.
      Returns:
        a new instance configured with a `long` `Counters.PathCounters`.