Class Scanner


  • public class Scanner
    extends java.lang.Object
    Recursively scan directories to process files.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  Scanner.Action
      Action interface passed to scan method to act on files.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.List<java.lang.String> patternsToSkip  
      private java.util.List<java.io.File> roots  
      private int verbose  
    • Constructor Summary

      Constructors 
      Constructor Description
      Scanner​(int verbose, java.io.File... files)  
      Scanner​(int verbose, java.util.List<java.io.File> files)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addDirectoryToSkip​(java.lang.String pattern)
      Add a pattern that defines a directory to skip.
      private boolean doScan​(java.io.File file, Scanner.Action action)  
      private boolean match​(java.lang.String pattern, java.lang.String fname)  
      boolean scan​(Scanner.Action action)
      Scan all files reachable from roots.
      private boolean skipDirectory​(java.io.File file)  
      • Methods inherited from class java.lang.Object

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

      • roots

        private final java.util.List<java.io.File> roots
      • verbose

        private final int verbose
      • patternsToSkip

        private java.util.List<java.lang.String> patternsToSkip
    • Constructor Detail

      • Scanner

        public Scanner​(int verbose,
                       java.util.List<java.io.File> files)
      • Scanner

        public Scanner​(int verbose,
                       java.io.File... files)
    • Method Detail

      • addDirectoryToSkip

        public void addDirectoryToSkip​(java.lang.String pattern)
        Add a pattern that defines a directory to skip. We only need really simple patterns: just a single name that must match a component of a directory name exactly.
      • scan

        public boolean scan​(Scanner.Action action)
                     throws java.io.IOException
        Scan all files reachable from roots. Does a depth-first search. Ignores all directories (and their contents) that match an entry in patternsToSkip. Passes each file (not directories) to the action. If action returns false, scan terminates. The result of the scan is the result of the last action call.
        Throws:
        java.io.IOException
      • doScan

        private boolean doScan​(java.io.File file,
                               Scanner.Action action)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • skipDirectory

        private boolean skipDirectory​(java.io.File file)
      • match

        private boolean match​(java.lang.String pattern,
                              java.lang.String fname)