Class Searcher


  • public class Searcher
    extends java.lang.Object
    Performs a multi-threaded search of a file tree and informs a listener of the results.
    Since:
    2.1a7
    Author:
    Chris Jennings
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  Searcher.ResultReceiver
      An interface that is sent search results and progress updates as the search proceeds.
    • Constructor Summary

      Constructors 
      Constructor Description
      Searcher​(Member parent, java.util.regex.Pattern pattern, Searcher.ResultReceiver receiver)
      Begins a new search in the background, passing matches to the specified receiver.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void cancel()
      Cancels the search before it completes.
      protected java.nio.charset.Charset getEncodingFor​(Member member)
      Returns the character encoding to use when scanning the specified member.
      int getFilesSearched()
      Returns the number of files that have been scanned so far.
      protected boolean isExcluded​(Member member)
      Returns true if the given member should be skipped by the searcher.
      protected void scanReader​(Member member, java.io.BufferedReader reader, boolean isBinaryType)
      Called to scan the contents of a file.
      • Methods inherited from class java.lang.Object

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

      • Searcher

        public Searcher​(Member parent,
                        java.util.regex.Pattern pattern,
                        Searcher.ResultReceiver receiver)
        Begins a new search in the background, passing matches to the specified receiver.
        Parameters:
        parent - the root of the tree at which the search should begin
        pattern - the regular expression to search for
        receiver - the receiver to be notified of search results as they become available
        Throws:
        java.lang.NullPointerException - if any parameter is null
    • Method Detail

      • getFilesSearched

        public int getFilesSearched()
        Returns the number of files that have been scanned so far.
        Returns:
        the number of scanned files
      • scanReader

        protected void scanReader​(Member member,
                                  java.io.BufferedReader reader,
                                  boolean isBinaryType)
                           throws java.io.IOException
        Called to scan the contents of a file.
        Parameters:
        member - the member being searched
        reader - a reader than can be used to read text content to be searched
        isBinaryType - true if the file is binary rather than a text file
        Throws:
        java.io.IOException - if an I/O error occurs while reading the file
      • isExcluded

        protected boolean isExcluded​(Member member)
        Returns true if the given member should be skipped by the searcher. (The base class returns false, meaning that all files are searched.)
        Parameters:
        member - the file to test
        Returns:
        true if the file should be excluded
      • getEncodingFor

        protected java.nio.charset.Charset getEncodingFor​(Member member)
        Returns the character encoding to use when scanning the specified member. If the file is a known text file type, the default encoding for that type will be returned. If the file is one of a small set of known binary file types, returns an encoding suitable for that file type. Otherwise, returns null to indicate that the file cannot be scanned.
        Parameters:
        member - the member to determine an encoding for
        Returns:
        an encoding to use for scanning, or null if none applies
        See Also:
        MetadataSource.getDefaultCharset(ca.cgjennings.apps.arkham.project.Member)
      • cancel

        public void cancel()
        Cancels the search before it completes.