Class SimpleFileScanner


  • public class SimpleFileScanner
    extends java.lang.Object
    Simple File Scanner (Single-Thread)

    This class provides a simple mechanism to scan files and directories using customizable filters. It supports both recursive and non-recursive scanning operations.

    Features

    • Scans files and directories based on provided filters.
    • Supports recursive scanning of subdirectories.
    • Returns an unmodifiable set of matched files, preserving order based on the underlying file system's implementation.

    Example Usage

    
     // Scan all files in the given directory (non-recursive)
     Set<File> files = SimpleFileScanner.INSTANCE.scan(new File("/your/path"), false);
    
     // Scan all files recursively under the given directory
     Set<File> recursiveFiles = SimpleFileScanner.INSTANCE.scan(new File("/your/path"), true);
    
     // Scan with custom filter (e.g., only .txt files)
     IOFileFilter filter = new IOFileFilter() {
         public boolean accept(File file) {
             return file.getName().endsWith(".txt");
         }
     };
     Set<File> txtFiles = SimpleFileScanner.INSTANCE.scan(new File("/your/path"), true, filter);
     
    Since:
    1.0.0
    Author:
    Mercy
    See Also:
    INSTANCE, IOFileFilter
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Set<java.io.File> scan​(java.io.File rootDirectory, boolean recursive)
      Scan all File Set under root directory
      java.util.Set<java.io.File> scan​(java.io.File rootDirectory, boolean recursive, IOFileFilter ioFileFilter)
      Scan all File Set that are accepted by IOFileFilter under root directory
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SimpleFileScanner

        public SimpleFileScanner()
    • Method Detail

      • scan

        @Nonnull
        @Immutable
        public java.util.Set<java.io.File> scan​(java.io.File rootDirectory,
                                                boolean recursive)
        Scan all File Set under root directory
        Parameters:
        rootDirectory - Root directory
        recursive - is recursive on sub directories
        Returns:
        Read-only Set , and the order be dependent on File.listFiles() implementation
        See Also:
        IOFileFilter
      • scan

        @Nonnull
        @Immutable
        public java.util.Set<java.io.File> scan​(java.io.File rootDirectory,
                                                boolean recursive,
                                                IOFileFilter ioFileFilter)
        Scan all File Set that are accepted by IOFileFilter under root directory
        Parameters:
        rootDirectory - Root directory
        recursive - is recursive on sub directories
        ioFileFilter - IOFileFilter
        Returns:
        Read-only Set , and the order be dependent on File.listFiles() implementation
        See Also:
        IOFileFilter