Class Searcher
- java.lang.Object
-
- ca.cgjennings.apps.arkham.project.Searcher
-
public class Searcher extends java.lang.ObjectPerforms 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 interfaceSearcher.ResultReceiverAn 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 voidcancel()Cancels the search before it completes.protected java.nio.charset.CharsetgetEncodingFor(Member member)Returns the character encoding to use when scanning the specified member.intgetFilesSearched()Returns the number of files that have been scanned so far.protected booleanisExcluded(Member member)Returnstrueif the given member should be skipped by the searcher.protected voidscanReader(Member member, java.io.BufferedReader reader, boolean isBinaryType)Called to scan the contents of a file.
-
-
-
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 beginpattern- the regular expression to search forreceiver- the receiver to be notified of search results as they become available- Throws:
java.lang.NullPointerException- if any parameter isnull
-
-
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 searchedreader- a reader than can be used to read text content to be searchedisBinaryType-trueif 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)
Returnstrueif the given member should be skipped by the searcher. (The base class returnsfalse, meaning that all files are searched.)- Parameters:
member- the file to test- Returns:
trueif 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, returnsnullto indicate that the file cannot be scanned.- Parameters:
member- the member to determine an encoding for- Returns:
- an encoding to use for scanning, or
nullif none applies - See Also:
MetadataSource.getDefaultCharset(ca.cgjennings.apps.arkham.project.Member)
-
cancel
public void cancel()
Cancels the search before it completes.
-
-