public final class MultithreadedScanner extends LocalScannerBase
ScannerExecutor
. This class handles the scanning of files, strings and buffers on multiple threads.settingsLoader
Constructor and Description |
---|
MultithreadedScanner(android.content.Context context)
Constructor.
|
MultithreadedScanner(android.content.Context context,
MultithreadedScanListener listener)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
cancelAndDestroy()
Cancels the scanner and all scans in progress.
|
void |
destroy()
Destroys the scanner.
|
int |
getActiveThreadCount()
Retrieves the number of threads that are currently running.
|
int |
getMaxThreadCount()
Retrieves the maximum number of threads that the scanner can use.
|
int |
getThreadExpiryTimeout()
Retrieves the expiry timeout of a thread.
|
void |
loadSettings(java.io.File settingsFile)
Loads the settings from a file.
|
void |
loadSettings(java.lang.String settings)
Loads the settings from a string.
|
void |
scanBuffer(byte[] buffer,
boolean stopAtFirstThreat,
java.lang.String fileName,
int priority)
Executes a buffer scan.
|
void |
scanBuffer(byte[] buffer,
ThreatHandler threatHandler,
java.lang.String fileName,
int priority)
Executes a buffer scan with a custom
ThreatHandler . |
void |
scanFile(java.io.File file,
boolean stopAtFirstThreat,
int priority)
Executes a file scan.
|
void |
scanFile(java.io.File file,
ThreatHandler threatHandler,
int priority)
Executes a file scan with a custom
ThreatHandler . |
void |
scanString(java.lang.String string,
boolean stopAtFirstThreat,
int priority)
Executes a string scan.
|
void |
scanString(java.lang.String string,
ThreatHandler threatHandler,
int priority)
Executes a string scan with a custom
ThreatHandler . |
void |
setMaxThreadCount(int maxThreads)
Sets the maximum number of threads that the scanner can use.
|
void |
setThreadExpiryTimeout(int millis)
Sets the expiry timeout of a thread.
|
void |
waitForFinished()
Blocks the current thread until the scanner finishes all scans.
|
checkScanBufferExceptions, checkScanBufferExceptions, checkScanFileExceptions, checkScanFileExceptions, checkScanStringExceptions, checkScanStringExceptions, checkWriteStoragePermission, isLicenseLoaded, isSettingsLoaded, loadLicense, loadLicense
public MultithreadedScanner(android.content.Context context) throws NoPermissionException
ThreatHandler
context
- The context.NoPermissionException
- If android.permission.WRITE_EXTERNAL_STORAGE is not granted.public MultithreadedScanner(android.content.Context context, MultithreadedScanListener listener) throws NoPermissionException
MultithreadedScanListener
.context
- The context.listener
- The MultithreadedScanListener
which receives the results.NoPermissionException
- If android.permission.WRITE_EXTERNAL_STORAGE is not granted.public void scanFile(java.io.File file, boolean stopAtFirstThreat, int priority) throws InvalidLicenseException, LicenseExpiredException, LicenseException, SettingsException, NoPermissionException, java.io.IOException, UnsupportedMimeTypeException, java.lang.Exception
MultithreadedScanListener
passed in the constructor.file
- The file to be scanned.stopAtFirstThreat
- If true, it will stop after the first threat is found. If false, it will scan the whole file.priority
- The priority of the file in the queue. Files with high priority will be scanned before the files with low priority.InvalidLicenseException
- If the license is invalid.LicenseExpiredException
- If the license is expired.LicenseException
- If the license is not loaded.SettingsException
- If the settings are invalid or not loaded.NoPermissionException
- If android.permission.WRITE_EXTERNAL_STORAGE is not granted.java.io.IOException
- If there was an error reading the file.UnsupportedMimeTypeException
- If this type of file cannot be scanned.java.lang.Exception
- Generic exception.public void scanFile(java.io.File file, ThreatHandler threatHandler, int priority) throws InvalidLicenseException, LicenseExpiredException, LicenseException, SettingsException, NoPermissionException, java.io.IOException, UnsupportedMimeTypeException, java.lang.Exception
ThreatHandler
.file
- The file to be scanned.threatHandler
- The custom handler that returns and handles the threat.priority
- The priority of the file in the queue. Files with high priority will be scanned before the files with low priority.InvalidLicenseException
- If the license is invalid.LicenseExpiredException
- If the license is expired.LicenseException
- If the license is not loaded.SettingsException
- If the settings are invalid or not loaded.NoPermissionException
- If android.permission.WRITE_EXTERNAL_STORAGE is not granted.java.io.IOException
- If there was an error reading the file.UnsupportedMimeTypeException
- If this type of file cannot be scanned.java.lang.Exception
- Generic exception.public void scanString(java.lang.String string, boolean stopAtFirstThreat, int priority) throws InvalidLicenseException, LicenseExpiredException, LicenseException, SettingsException, NoPermissionException, java.lang.Exception
MultithreadedScanListener
passed in the constructor.string
- The string to be scanned.stopAtFirstThreat
- If true, it will stop after the first threat is found. If false, it will scan the whole string.priority
- The priority of the string in the queue. Strings with high priority will be scanned before the strings with low priority.InvalidLicenseException
- If the license is invalid.LicenseExpiredException
- If the license is expired.LicenseException
- If the license is not loaded.SettingsException
- If the settings are invalid or not loaded.NoPermissionException
- If android.permission.WRITE_EXTERNAL_STORAGE is not granted.java.lang.Exception
- Generic exception.public void scanString(java.lang.String string, ThreatHandler threatHandler, int priority) throws InvalidLicenseException, LicenseExpiredException, LicenseException, SettingsException, NoPermissionException, java.lang.Exception
ThreatHandler
.string
- The string to be scanned.threatHandler
- The custom handler that returns and handles the threat.priority
- The priority of the string in the queue. Strings with high priority will be scanned before the strings with low priority.InvalidLicenseException
- If the license is invalid.LicenseExpiredException
- If the license is expired.LicenseException
- If the license is not loaded.SettingsException
- If the settings are invalid or not loaded.NoPermissionException
- If android.permission.WRITE_EXTERNAL_STORAGE is not granted.java.lang.Exception
- Generic exception.public void scanBuffer(byte[] buffer, boolean stopAtFirstThreat, java.lang.String fileName, int priority) throws InvalidLicenseException, LicenseExpiredException, LicenseException, SettingsException, NoPermissionException, java.lang.Exception
MultithreadedScanListener
passed in the constructor.buffer
- The buffer to be scanned.stopAtFirstThreat
- If true, it will stop after the first threat is found. If false, it will scan the whole buffer.fileName
- If you scan the buffer from a file, specify the file name.priority
- The priority of the buffer in the queue. Buffers with high priority will be scanned before the buffers with low priority.InvalidLicenseException
- If the license is invalid.LicenseExpiredException
- If the license is expired.LicenseException
- If the license is not loaded.SettingsException
- If the settings are invalid or not loaded.NoPermissionException
- If android.permission.WRITE_EXTERNAL_STORAGE is not granted.java.lang.Exception
- Generic exception.public void scanBuffer(byte[] buffer, ThreatHandler threatHandler, java.lang.String fileName, int priority) throws InvalidLicenseException, LicenseExpiredException, LicenseException, SettingsException, NoPermissionException, java.lang.Exception
ThreatHandler
.buffer
- The buffer to be scanned.threatHandler
- The custom handler that returns and handles the threat.fileName
- If you scan the buffer from a file, specify the file name.priority
- The priority of the buffer in the queue. Buffers with high priority will be scanned before the buffers with low priority.InvalidLicenseException
- If the license is invalid.LicenseExpiredException
- If the license is expired.LicenseException
- If the license is not loaded.SettingsException
- If the settings are invalid or not loaded.NoPermissionException
- If android.permission.WRITE_EXTERNAL_STORAGE is not granted.java.lang.Exception
- Generic exception.public void loadSettings(java.io.File settingsFile) throws SettingsException, NoPermissionException, java.io.IOException, java.lang.Exception
loadSettings
in class LocalScannerBase
settingsFile
- The file containing the settings.SettingsException
- If there was an error loading the settings.NoPermissionException
- If android.permission.WRITE_EXTERNAL_STORAGE is not granted.java.io.IOException
- If there was an error reading the file.java.lang.Exception
- Generic exception.public void loadSettings(java.lang.String settings) throws SettingsException, NoPermissionException, java.lang.Exception
loadSettings
in class LocalScannerBase
settings
- The string containing the settings.SettingsException
- If there was an error loading the settings.NoPermissionException
- If android.permission.WRITE_EXTERNAL_STORAGE is not granted.java.lang.Exception
- Generic exception.public void setMaxThreadCount(int maxThreads)
maxThreads
- The maximum number of threads.public int getMaxThreadCount()
public void setThreadExpiryTimeout(int millis)
millis
- The expiry timeout of a thread in milliseconds.public int getThreadExpiryTimeout()
public int getActiveThreadCount()
public void waitForFinished()
public void cancelAndDestroy()
MultithreadedScanner
will be destroyed and cannot be used again. This automatically destroys the scanner, so destroy()
method is not needed to be called after this.public void destroy()