### Install ClamAV Client with Gradle Source: https://context7.com/cdarras/clamav-client/llms.txt Add the ClamAV Client library to your project's Gradle dependencies. ```gradle implementation 'xyz.capybara:clamav-client:2.1.3' ``` -------------------------------- ### Get ClamAV Daemon Version Source: https://github.com/cdarras/clamav-client/blob/master/README.md Requests and returns the version string of the ClamAV daemon. ```java String version(); ``` -------------------------------- ### Get ClamAV Daemon Version Source: https://github.com/cdarras/clamav-client/blob/master/README.md Requests the version of the ClamAV daemon. ```APIDOC ## Get ClamAV Daemon Version ### Description Requests the version of the ClamAV daemon. ### Method ```java String version() ``` ``` -------------------------------- ### Get ClamAV Daemon Stats Source: https://github.com/cdarras/clamav-client/blob/master/README.md Requests stats from the ClamAV daemon. ```APIDOC ## Get ClamAV Daemon Stats ### Description Requests stats from the ClamAV daemon. ### Method ```java String stats() ``` ``` -------------------------------- ### Get ClamAV Daemon Stats Source: https://github.com/cdarras/clamav-client/blob/master/README.md Requests and returns statistics from the ClamAV daemon. ```java String stats(); ``` -------------------------------- ### ClamavClient Instantiation Source: https://context7.com/cdarras/clamav-client/llms.txt Demonstrates how to create an instance of the ClamavClient, connecting to a ClamAV daemon with various configuration options including hostname, port, and server platform. ```APIDOC ## ClamavClient — Client Instantiation Creates a client connected to a ClamAV daemon. Overloaded constructors allow specifying just a hostname (using default port `3310`), a hostname and port, a hostname with an explicit server `Platform`, or a raw `InetSocketAddress`. The `Platform` enum (`UNIX`, `WINDOWS`, `JVM_PLATFORM`) controls the path separator used when scanning files on the server filesystem. ### Kotlin Example ```kotlin import xyz.capybara.clamav.ClamavClient import xyz.capybara.clamav.Platform import java.net.InetSocketAddress // Simplest form — connects to localhost:3310 val client = ClamavClient("localhost") // Custom port val client2 = ClamavClient("clamav.internal", 3311) // Cross-platform: Java app on Windows, ClamAV daemon on Linux val client3 = ClamavClient("clamav.internal", 3310, Platform.UNIX) // Using a raw socket address val client4 = ClamavClient(InetSocketAddress("clamav.internal", 3310), Platform.UNIX) ``` ### Java Example ```java // Java usage ClamavClient client = new ClamavClient("localhost"); ClamavClient clientWithPort = new ClamavClient("localhost", 3311); ClamavClient clientCrossPlatform = new ClamavClient("clamav.internal", 3310, Platform.UNIX); ``` ``` -------------------------------- ### Instantiate ClamavClient in Java Source: https://context7.com/cdarras/clamav-client/llms.txt Create instances of ClamavClient in Java with different constructor overloads for host, port, and platform. ```java // Java usage ClamavClient client = new ClamavClient("localhost"); ClamavClient clientWithPort = new ClamavClient("localhost", 3311); ClamavClient clientCrossPlatform = new ClamavClient("clamav.internal", 3310, Platform.UNIX); ``` -------------------------------- ### Instantiate ClamavClient in Kotlin Source: https://context7.com/cdarras/clamav-client/llms.txt Create instances of ClamavClient with various connection configurations, including default host/port, custom ports, and explicit server platforms. ```kotlin import xyz.capybara.clamav.ClamavClient import xyz.capybara.clamav.Platform import java.net.InetSocketAddress // Simplest form — connects to localhost:3310 val client = ClamavClient("localhost") // Custom port val client2 = ClamavClient("clamav.internal", 3311) // Cross-platform: Java app on Windows, ClamAV daemon on Linux val client3 = ClamavClient("clamav.internal", 3310, Platform.UNIX) // Using a raw socket address val client4 = ClamavClient(InetSocketAddress("clamav.internal", 3310), Platform.UNIX) ``` -------------------------------- ### Handle ScanResult - OK and VirusFound Source: https://context7.com/cdarras/clamav-client/llms.txt Demonstrates how to handle the sealed ScanResult class, differentiating between a clean scan (ScanResult.OK) and a scan where viruses were found (ScanResult.VirusFound). For stream scans, the key in foundViruses is 'stream'; for file system scans, it's the absolute file path. ```kotlin import xyz.capybara.clamav.commands.scan.result.ScanResult fun handleResult(result: ScanResult) { when (result) { is ScanResult.OK -> { println("Scan passed — no threats detected") } is ScanResult.VirusFound -> { println("Threats found in ${result.foundViruses.size} location(s):") result.foundViruses.forEach { (location, virusNames) -> println(" [$location] → ${virusNames.joinToString()}") } } } } ``` -------------------------------- ### Instantiate ClamAV Client with Custom Port Source: https://github.com/cdarras/clamav-client/blob/master/README.md Create a ClamAV client instance connecting to localhost on a specified port. ```java ClamavClient client = new ClamavClient("localhost", 3311); ``` -------------------------------- ### Instantiate ClamAV Client with Default Port Source: https://github.com/cdarras/clamav-client/blob/master/README.md Create a ClamAV client instance connecting to localhost on the default port 3310. ```java ClamavClient client = new ClamavClient("localhost"); ``` -------------------------------- ### Build ClamAV Client from Sources with Maven Source: https://github.com/cdarras/clamav-client/blob/master/README.md Use this command to clean, package, and build the library from its source code. The resulting jar file will be located in the 'target' directory upon successful completion. ```maven mvn clean package ``` -------------------------------- ### Instantiate ClamAV Client with Custom Port and Remote UNIX Server Source: https://github.com/cdarras/clamav-client/blob/master/README.md Instantiate the client specifying a custom port and the remote server's platform as UNIX. ```java ClamavClient client = new ClamavClient("localhost", 3311, Platform.UNIX); ``` -------------------------------- ### Scan Server Filesystem Path (Kotlin) Source: https://context7.com/cdarras/clamav-client/llms.txt Scans a file or directory on the ClamAV daemon's filesystem. By default, scanning stops at the first virus found. Set `continueScan = true` to scan all files and collect all infected paths. ```kotlin import xyz.capybara.clamav.ClamavClient import xyz.capybara.clamav.Platform import xyz.capybara.clamav.commands.scan.result.ScanResult import java.nio.file.Paths // ClamAV daemon is on a Linux host; client also on Linux val client = ClamavClient("clamav.internal", Platform.UNIX) // Scan a single file — stop at first virus val filePath = Paths.get("/srv/uploads/report.docx") val result = client.scan(filePath) when (result) { is ScanResult.OK -> println("Clean") is ScanResult.VirusFound -> println("Found: ${result.foundViruses}") // Output: Found: {/srv/uploads/report.docx=[Win.Trojan.Agent]} } // Scan an entire directory — continue past first virus to find all infected files val dirPath = Paths.get("/srv/uploads") val fullResult = client.scan(dirPath, continueScan = true) if (fullResult is ScanResult.VirusFound) { fullResult.foundViruses.forEach { (path, viruses) -> println("Infected file: $path → $viruses") } } ``` -------------------------------- ### Parallel Scan Server Filesystem Directory (Kotlin) Source: https://context7.com/cdarras/clamav-client/llms.txt Triggers a multi-threaded scan of a directory on the ClamAV daemon's filesystem using the MULTISCAN command. This method scans all files to completion and collects all infected file paths. ```kotlin import xyz.capybara.clamav.ClamavClient import xyz.capybara.clamav.Platform import xyz.capybara.clamav.commands.scan.result.ScanResult import java.nio.file.Paths val client = ClamavClient("clamav.internal", Platform.UNIX) val uploadDir = Paths.get("/srv/quarantine") val result = client.parallelScan(uploadDir) when (result) { is ScanResult.OK -> println("All files clean") is ScanResult.VirusFound -> { println("${result.foundViruses.size} infected file(s) found:") result.foundViruses.forEach { (path, viruses) -> println(" $path: $viruses") } // Output: // 2 infected file(s) found: // /srv/quarantine/eicar.txt: [Eicar-Signature] // /srv/quarantine/eicar_copy.txt: [Eicar-Signature] } } ``` -------------------------------- ### Instantiate ClamAV Client for Remote UNIX Server Source: https://github.com/cdarras/clamav-client/blob/master/README.md Instantiate the client specifying the remote server's platform as UNIX, useful when the Java application and ClamAV daemon are on different OS types. ```java ClamavClient client = new ClamavClient("localhost", Platform.UNIX); ``` -------------------------------- ### Handle ClamAV Scan Results in Java Source: https://github.com/cdarras/clamav-client/blob/master/README.md Demonstrates how to check the ScanResult type and access found viruses in Java. The result can be ScanResult.OK or ScanResult.VirusFound. ```java if (scanResult instanceof ScanResult.OK) { // OK } else if (scanResult instanceof ScanResult.VirusFound) { Map> viruses = ((ScanResult.VirusFound) scanResult).getFoundViruses(); } ``` -------------------------------- ### version Source: https://context7.com/cdarras/clamav-client/llms.txt Requests and retrieves the version string of the ClamAV daemon. Handles potential communication errors by throwing a ClamavException. ```APIDOC ## version — Daemon Version Query Requests and returns the version string of the running ClamAV daemon, e.g. `"ClamAV 0.105.1/26773/..."`. ### Example ```kotlin val client = ClamavClient("localhost") try { val version = client.version() println("ClamAV version: $version") // Output: ClamAV version: ClamAV 0.105.1/26773/Wed Jan 4 08:10:36 2023 } catch (e: ClamavException) { println("Failed to get version: ${e.cause?.message}") } ``` ``` -------------------------------- ### Query Daemon Version with version (Kotlin) Source: https://context7.com/cdarras/clamav-client/llms.txt Retrieve the version string of the ClamAV daemon by calling the version() method. Handles potential ClamavExceptions during the process. ```kotlin val client = ClamavClient("localhost") try { val version = client.version() println("ClamAV version: $version") // Output: ClamAV version: ClamAV 0.105.1/26773/Wed Jan 4 08:10:36 2023 } catch (e: ClamavException) { println("Failed to get version: ${e.cause?.message}") } ``` -------------------------------- ### Exception Handling Source: https://context7.com/cdarras/clamav-client/llms.txt Demonstrates how to catch and inspect `ClamavException` and its causes to handle specific errors like communication issues, invalid responses, or scan failures. ```APIDOC ## Exception Types ### Description The library defines a hierarchy of typed exceptions, all wrapped in `ClamavException` when thrown from public API methods. Catching `ClamavException` and inspecting its `cause` gives access to the specific failure reason. ### Method N/A (Exception handling pattern) ### Endpoint N/A ### Request Example ```kotlin import xyz.capybara.clamav.* val client = ClamavClient("localhost") try { client.ping() } catch (e: ClamavException) { when (val cause = e.cause) { is CommunicationException -> println("Network/IO error: ${cause.message}") is InvalidResponseException -> println("Unexpected daemon response: ${cause.message}") is ScanFailureException -> println("Scan internal failure: ${cause.message}") is UnsupportedCommandException -> println("Command not supported by this daemon version: ${cause.message}") is UnknownCommandException -> println("Daemon did not recognize command: ${cause.message}") else -> println("Unknown error: ${cause?.message}") } } ``` ### Response N/A (This section describes error handling, not typical responses) ``` -------------------------------- ### Handle ClamavException with Specific Causes Source: https://context7.com/cdarras/clamav-client/llms.txt Demonstrates how to catch ClamavException and inspect its 'cause' property to handle specific communication, response, or command-related errors. This allows for more granular error management. ```kotlin import xyz.capybara.clamav.* val client = ClamavClient("localhost") try { client.ping() } catch (e: ClamavException) { when (val cause = e.cause) { is CommunicationException -> println("Network/IO error: ${cause.message}") is InvalidResponseException -> println("Unexpected daemon response: ${cause.message}") is ScanFailureException -> println("Scan internal failure: ${cause.message}") is UnsupportedCommandException -> println("Command not supported by this daemon version: ${cause.message}") is UnknownCommandException -> println("Daemon did not recognize command: ${cause.message}") else -> println("Unknown error: ${cause?.message}") } } ``` -------------------------------- ### Handle ClamAV Scan Results in Kotlin Source: https://github.com/cdarras/clamav-client/blob/master/README.md Shows how to process ScanResult in Kotlin using a 'when' expression for cleaner type checking and smart-casting. ```kotlin when (scanResult) { is ScanResult.OK -> // OK is ScanResult.VirusFound -> scanResult.foundViruses } ``` -------------------------------- ### Retrieve Daemon Statistics with stats (Kotlin) Source: https://context7.com/cdarras/clamav-client/llms.txt Fetch multi-line statistics from the ClamAV daemon using the stats() method. This includes information on thread pool, queue depth, and memory usage. Catches ClamavExceptions. ```kotlin val client = ClamavClient("localhost") try { val stats = client.stats() println(stats) // Output (example): // POOLS: 1 // STATE: VALID PRIMARY // THREADS: live 1 idle 0 max 10 idle-timeout 30 // QUEUE: 0 items // ... } catch (e: ClamavException) { println("Failed to retrieve stats: ${e.cause?.message}") } ``` -------------------------------- ### Check Daemon Connectivity with isReachable (Kotlin) Source: https://context7.com/cdarras/clamav-client/llms.txt Use the isReachable method to check if the ClamAV daemon is responsive within a specified timeout. This is useful for health checks without throwing exceptions. ```kotlin val client = ClamavClient("localhost") // Default timeout: 3000 ms if (client.isReachable()) { println("ClamAV is up") } else { println("ClamAV is not reachable") } // Custom timeout: 500 ms val ready = client.isReachable(timeout = 500) println("Reachable: $ready") ``` -------------------------------- ### shutdownServer Source: https://context7.com/cdarras/clamav-client/llms.txt Sends the SHUTDOWN command to gracefully stop the ClamAV daemon process. Use `isReachable()` afterward to verify termination. ```APIDOC ## shutdownServer ### Description Sends the `SHUTDOWN` command, immediately stopping the ClamAV daemon process. Use `isReachable()` afterward to verify the daemon has terminated. ### Method POST (or equivalent command) ### Endpoint N/A (Command-based) ### Request Example ```kotlin import kotlinx.coroutines.delay import xyz.capybara.clamav.ClamavClient val client = ClamavClient("localhost") try { client.shutdownServer() println("Shutdown command sent") } catch (e: ClamavException) { println("Shutdown error: ${e.cause?.message}") } // Verify daemon stopped (give it a moment to terminate) Thread.sleep(2000) println("Daemon reachable after shutdown: ${client.isReachable()}") // Output: Daemon reachable after shutdown: false ``` ### Response #### Success Response Indicates the shutdown command was processed successfully by the daemon. #### Response Example (No specific response body detailed, success is indicated by lack of exception) ``` -------------------------------- ### parallelScan(Path) Source: https://context7.com/cdarras/clamav-client/llms.txt Sends the `MULTISCAN` command, which instructs the ClamAV daemon to scan a directory using multiple threads (SMP-optimized). Scans all files to completion regardless of findings. Returns a `ScanResult` with all infected file paths collected. ```APIDOC ## parallelScan(Path) ### Description Sends the `MULTISCAN` command, which instructs the ClamAV daemon to scan a directory using multiple threads (SMP-optimized). Scans all files to completion regardless of findings. Returns a `ScanResult` with all infected file paths collected. ### Method Signature `parallelScan(path: Path): ScanResult` ### Parameters * **path** (Path) - The path to the directory on the ClamAV daemon's filesystem to be scanned. ### Request Example (Kotlin) ```kotlin import xyz.capybara.clamav.ClamavClient import xyz.capybara.clamav.Platform import xyz.capybara.clamav.commands.scan.result.ScanResult import java.nio.file.Paths val client = ClamavClient("clamav.internal", Platform.UNIX) val uploadDir = Paths.get("/srv/quarantine") val result = client.parallelScan(uploadDir) when (result) { is ScanResult.OK -> println("All files clean") is ScanResult.VirusFound -> { println("${result.foundViruses.size} infected file(s) found:") result.foundViruses.forEach { (path, viruses) -> println(" $path: $viruses") } } } ``` ### Response * **ScanResult.OK**: Indicates all files in the scanned directory are clean. * **ScanResult.VirusFound**: Indicates one or more viruses were found. Contains a map of infected file paths to lists of viruses found. ``` -------------------------------- ### Add Gradle Dependency for ClamAV Client Source: https://github.com/cdarras/clamav-client/blob/master/README.md Add this dependency to your build.gradle file to integrate the ClamAV client library. ```gradle compile 'xyz.capybara:clamav-client:2.1.3' ``` -------------------------------- ### Scan File/Directory on Filesystem Source: https://github.com/cdarras/clamav-client/blob/master/README.md Scans a file or directory on the filesystem of the ClamAV daemon. ```APIDOC ## Scan File/Directory on Filesystem ### Description Scans a file/directory on the filesystem of the ClamAV daemon and sends a response as soon as a virus has been found. ### Method ```java ScanResult scan(Path path) ``` ``` -------------------------------- ### Perform Daemon Health Check with ping (Kotlin) Source: https://context7.com/cdarras/clamav-client/llms.txt Send a PING command to the ClamAV daemon using the ping() method. It returns normally on success or throws a ClamavException if communication fails. ```kotlin import xyz.capybara.clamav.ClamavClient import xyz.capybara.clamav.ClamavException val client = ClamavClient("localhost") try { client.ping() println("Daemon is alive") } catch (e: ClamavException) { println("Daemon not responding: ${e.cause?.message}") } ``` -------------------------------- ### Shutdown ClamAV Daemon Source: https://context7.com/cdarras/clamav-client/llms.txt Sends the SHUTDOWN command to gracefully stop the ClamAV daemon process. Use isReachable() afterward to verify the daemon has terminated. A small delay is included before checking reachability. ```kotlin import kotlinx.coroutines.delay import xyz.capybara.clamav.ClamavClient val client = ClamavClient("localhost") try { client.shutdownServer() println("Shutdown command sent") } catch (e: ClamavException) { println("Shutdown error: ${e.cause?.message}") } // Verify daemon stopped (give it a moment to terminate) Thread.sleep(2000) println("Daemon reachable after shutdown: ${client.isReachable()}") ``` -------------------------------- ### Add Maven Dependency for ClamAV Client Source: https://github.com/cdarras/clamav-client/blob/master/README.md Include this dependency in your pom.xml to use the ClamAV client library. ```xml xyz.capybara clamav-client 2.1.3 ``` -------------------------------- ### Scan InputStream with ClamAV Client (Java) Source: https://context7.com/cdarras/clamav-client/llms.txt Java usage for scanning an InputStream with the ClamAV client. Handles ScanResult.OK and ScanResult.VirusFound, and includes basic error handling for ClamavException and IOException. ```java import xyz.capybara.clamav.ClamavClient; import xyz.capybara.clamav.commands.scan.result.ScanResult; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Collection; import java.util.Map; // Java usage ClamavClient client = new ClamavClient("localhost"); try (InputStream stream = new FileInputStream("/tmp/file.pdf")) { ScanResult result = client.scan(stream); if (result instanceof ScanResult.OK) { System.out.println("Clean"); } else if (result instanceof ScanResult.VirusFound) { Map> viruses = ((ScanResult.VirusFound) result).getFoundViruses(); System.out.println("Infected: " + viruses); } } catch (ClamavException | IOException e) { e.printStackTrace(); } ``` -------------------------------- ### Scan InputStream with ClamAV Client (Kotlin) Source: https://context7.com/cdarras/clamav-client/llms.txt Scans arbitrary byte data from an InputStream using the INSTREAM protocol. The default chunk size is 2048 bytes and can be overridden. This is suitable for uploaded files or in-memory content. ```kotlin import xyz.capybara.clamav.ClamavClient import xyz.capybara.clamav.ClamavException import xyz.capybara.clamav.commands.scan.result.ScanResult import java.io.File val client = ClamavClient("localhost") // Scan an uploaded file's InputStream val uploadedFile = File("/tmp/uploaded-document.pdf") try { val result = uploadedFile.inputStream().use { stream -> client.scan(stream) } when (result) { is ScanResult.OK -> println("File is clean") is ScanResult.VirusFound -> { println("Virus detected!") result.foundViruses.forEach { (location, viruses) -> println(" Location: $location, Viruses: $viruses") } // Output: Location: stream, Viruses: [Eicar-Signature] } } } catch (e: ClamavException) { println("Scan error: ${e.cause?.message}") } // Scan with a custom chunk size (e.g., 4096 bytes) val result2 = client.scan(uploadedFile.inputStream(), chunkSize = 4096) ``` -------------------------------- ### Scan File System Path with Continue Option Source: https://github.com/cdarras/clamav-client/blob/master/README.md Scans a file or directory on the ClamAV daemon's filesystem. The `continueScan` argument determines if the scan proceeds after a virus is detected. ```java ScanResult scan(Path path, boolean continueScan); ``` -------------------------------- ### Scan File System Path with ClamAV Source: https://github.com/cdarras/clamav-client/blob/master/README.md Scans a file or directory on the ClamAV daemon's filesystem. The scan stops as soon as a virus is found. ```java ScanResult scan(Path path); ``` -------------------------------- ### Scan File/Directory with Continue Option Source: https://github.com/cdarras/clamav-client/blob/master/README.md Scans a file or directory on the filesystem of the ClamAV daemon and may continue the scan to the end even if a virus has been found, depending on the `continueScan` argument. ```APIDOC ## Scan File/Directory with Continue Option ### Description Scans a file/directory on the filesystem of the ClamAV daemon and may continue the scan to the end even if a virus has been found, depending on the `continueScan` argument. ### Method ```java ScanResult scan(Path path, boolean continueScan) ``` ``` -------------------------------- ### scan(Path) Source: https://context7.com/cdarras/clamav-client/llms.txt Triggers a scan of a file or directory that exists on the ClamAV daemon's filesystem (not the client's). By default (`continueScan = false`) the scan stops at the first virus found. Set `continueScan = true` to scan all files even after a virus is discovered, collecting all infected paths. ```APIDOC ## scan(Path) ### Description Triggers a scan of a file or directory that exists on the ClamAV **daemon's** filesystem (not the client's). By default (`continueScan = false`) the scan stops at the first virus found. Set `continueScan = true` to scan all files even after a virus is discovered, collecting all infected paths. ### Method Signature `scan(path: Path, continueScan: Boolean = false): ScanResult` ### Parameters * **path** (Path) - The path to the file or directory on the ClamAV daemon's filesystem. * **continueScan** (Boolean, optional) - If true, the scan continues after finding the first virus to report all infected files. Defaults to false. ### Request Example (Kotlin) ```kotlin import xyz.capybara.clamav.ClamavClient import xyz.capybara.clamav.Platform import xyz.capybara.clamav.commands.scan.result.ScanResult import java.nio.file.Paths val client = ClamavClient("clamav.internal", Platform.UNIX) // Scan a single file — stop at first virus val filePath = Paths.get("/srv/uploads/report.docx") val result = client.scan(filePath) when (result) { is ScanResult.OK -> println("Clean") is ScanResult.VirusFound -> println("Found: ${result.foundViruses}") } // Scan an entire directory — continue past first virus to find all infected files val dirPath = Paths.get("/srv/uploads") val fullResult = client.scan(dirPath, continueScan = true) if (fullResult is ScanResult.VirusFound) { fullResult.foundViruses.forEach { (path, viruses) -> println("Infected file: $path → $viruses") } } ``` ### Response * **ScanResult.OK**: Indicates the scanned file or directory is clean. * **ScanResult.VirusFound**: Indicates one or more viruses were found. Contains a map of file paths to lists of viruses found. ``` -------------------------------- ### Scan InputStream with ClamAV Source: https://github.com/cdarras/clamav-client/blob/master/README.md Scans an InputStream for viruses. The chunkSize parameter controls the size of data chunks sent to the ClamAV daemon. Defaults to 2048 bytes. ```java ScanResult scan(InputStream inputStream, Integer chunkSize) ``` -------------------------------- ### scan(InputStream) Source: https://context7.com/cdarras/clamav-client/llms.txt Streams arbitrary byte data to the ClamAV daemon via the INSTREAM protocol and returns a ScanResult immediately when a virus is detected. The default chunk size is 2048 bytes and can be overridden. This is the primary method for scanning uploaded files, network payloads, or in-memory content without writing to disk. ```APIDOC ## scan(InputStream) ### Description Streams arbitrary byte data to the ClamAV daemon via the `INSTREAM` protocol and returns a `ScanResult` immediately when a virus is detected. The default chunk size is 2048 bytes and can be overridden. This is the primary method for scanning uploaded files, network payloads, or in-memory content without writing to disk. ### Method Signature `scan(inputStream: InputStream, chunkSize: Int = 2048): ScanResult` ### Parameters * **inputStream** (InputStream) - The stream of data to scan. * **chunkSize** (Int, optional) - The size of chunks to send to the daemon. Defaults to 2048 bytes. ### Request Example (Kotlin) ```kotlin import xyz.capybara.clamav.ClamavClient import xyz.capybara.clamav.ClamavException import xyz.capybara.clamav.commands.scan.result.ScanResult import java.io.File val client = ClamavClient("localhost") val uploadedFile = File("/tmp/uploaded-document.pdf") try { val result = uploadedFile.inputStream().use { client.scan(it) } when (result) { is ScanResult.OK -> println("File is clean") is ScanResult.VirusFound -> { println("Virus detected!") result.foundViruses.forEach { (location, viruses) -> println(" Location: $location, Viruses: $viruses") } } } } catch (e: ClamavException) { println("Scan error: ${e.cause?.message}") } ``` ### Request Example (Java) ```java import xyz.capybara.clamav.ClamavClient; import xyz.capybara.clamav.ClamavException; import xyz.capybara.clamav.commands.scan.result.ScanResult; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Collection; import java.util.Map; ClamavClient client = new ClamavClient("localhost"); try (InputStream stream = new FileInputStream("/tmp/file.pdf")) { ScanResult result = client.scan(stream); if (result instanceof ScanResult.OK) { System.out.println("Clean"); } else if (result instanceof ScanResult.VirusFound) { Map> viruses = ((ScanResult.VirusFound) result).getFoundViruses(); System.out.println("Infected: " + viruses); } } catch (ClamavException | IOException e) { e.printStackTrace(); } ``` ### Response * **ScanResult.OK**: Indicates the scanned data is clean. * **ScanResult.VirusFound**: Indicates one or more viruses were found. Contains a map of locations to lists of viruses found. * **ClamavException**: Thrown if an error occurs during the scan. ``` -------------------------------- ### Parallel Scan File/Directory Source: https://github.com/cdarras/clamav-client/blob/master/README.md Scans a file or directory on the filesystem of the ClamAV daemon and will continue the scan to the end even if a virus has been found. This method may improve performances on SMP systems by performing a multi-threaded scan. ```APIDOC ## Parallel Scan File/Directory ### Description Scans a file/directory on the filesystem of the ClamAV daemon and will continue the scan to the end even if a virus has been found. This method may improve performances on SMP systems by performing a multi-threaded scan. ### Method ```java ScanResult parallelScan(Path path) ``` ``` -------------------------------- ### Shutdown Server Source: https://github.com/cdarras/clamav-client/blob/master/README.md Immediately shutdowns the ClamAV daemon. ```APIDOC ## Shutdown Server ### Description Immediately shutdowns the ClamAV daemon. ### Method ```java void shutdownServer() ``` ``` -------------------------------- ### Reload Virus Databases Source: https://context7.com/cdarras/clamav-client/llms.txt Triggers the ClamAV daemon to reload its virus signature databases from disk by sending the RELOAD command. Use this after updating virus definition files without restarting the daemon. ```kotlin val client = ClamavClient("localhost") try { client.reloadVirusDatabases() println("Virus databases reloaded successfully") } catch (e: ClamavException) { println("Reload failed: ${e.cause?.message}") } ``` -------------------------------- ### Parallel Scan File System Path with ClamAV Source: https://github.com/cdarras/clamav-client/blob/master/README.md Scans a file or directory on the ClamAV daemon's filesystem, continuing the scan even after a virus is found. This method may offer performance improvements on multi-core systems through multi-threading. ```java ScanResult parallelScan(Path path); ``` -------------------------------- ### Scan InputStream Source: https://github.com/cdarras/clamav-client/blob/master/README.md Scans an InputStream for viruses. The chunkSize can be used to control the size of the chunk sent to ClamAV. Defaults to 2048 bytes. ```APIDOC ## Scan InputStream ### Description Scans an `InputStream` and sends a response as soon as a virus has been found. The `chunkSize` can be used to control the size of the chunk sent to ClamAV. Defaults to `2048` bytes. ### Method ```java ScanResult scan(InputStream inputStream, Integer chunkSize) ``` ``` -------------------------------- ### stats Source: https://context7.com/cdarras/clamav-client/llms.txt Fetches and returns a multi-line statistics string from the ClamAV daemon, providing insights into its operational status like thread pool usage and memory consumption. Catches communication errors with ClamavException. ```APIDOC ## stats — Daemon Statistics Requests a multi-line statistics string from the ClamAV daemon containing thread pool usage, queue depth, memory usage, and more. ### Example ```kotlin val client = ClamavClient("localhost") try { val stats = client.stats() println(stats) // Output (example): // POOLS: 1 // STATE: VALID PRIMARY // THREADS: live 1 idle 0 max 10 idle-timeout 30 // QUEUE: 0 items // ... } catch (e: ClamavException) { println("Failed to retrieve stats: ${e.cause?.message}") } ``` ``` -------------------------------- ### reloadVirusDatabases Source: https://context7.com/cdarras/clamav-client/llms.txt Sends the RELOAD command to the ClamAV daemon, triggering it to reload its virus signature databases from disk. This is useful after updating definition files without restarting the daemon. ```APIDOC ## reloadVirusDatabases ### Description Sends the `RELOAD` command, triggering the ClamAV daemon to reload its virus signature databases from disk. Use this after updating virus definition files without restarting the daemon. ### Method POST (or equivalent command) ### Endpoint N/A (Command-based) ### Request Example ```kotlin val client = ClamavClient("localhost") try { client.reloadVirusDatabases() println("Virus databases reloaded successfully") } catch (e: ClamavException) { println("Reload failed: ${e.cause?.message}") } ``` ### Response #### Success Response Indicates the reload command was processed successfully by the daemon. #### Response Example (No specific response body detailed, success is indicated by lack of exception) ``` -------------------------------- ### Reload Virus Databases Source: https://github.com/cdarras/clamav-client/blob/master/README.md Triggers the virus databases reloading by the ClamAV daemon. ```APIDOC ## Reload Virus Databases ### Description Triggers the virus databases reloading by the ClamAV daemon. ### Method ```java void reloadVirusDatabases() ``` ``` -------------------------------- ### Ping ClamAV Daemon Source: https://github.com/cdarras/clamav-client/blob/master/README.md Pings the ClamAV daemon. If a correct response has been received, the method simply returns. Otherwise, a `ClamavException` exception is thrown. ```APIDOC ## Ping ClamAV Daemon ### Description Pings the ClamAV daemon. If a correct response has been received, the method simply returns. Otherwise, a `ClamavException` exception is thrown. ### Method ```java void ping() ``` ``` -------------------------------- ### isReachable Source: https://context7.com/cdarras/clamav-client/llms.txt Checks if the ClamAV daemon is reachable by attempting a socket connection within a specified timeout. Returns true if reachable, false otherwise, without throwing exceptions. ```APIDOC ## isReachable — Daemon Connectivity Check Attempts a socket connection to the ClamAV daemon and returns `true` if it responds within the given timeout, `false` otherwise. Useful for health checks and readiness probes without throwing exceptions. ### Example ```kotlin val client = ClamavClient("localhost") // Default timeout: 3000 ms if (client.isReachable()) { println("ClamAV is up") } else { println("ClamAV is not reachable") } // Custom timeout: 500 ms val ready = client.isReachable(timeout = 500) println("Reachable: $ready") ``` ``` -------------------------------- ### Ping ClamAV Daemon Source: https://github.com/cdarras/clamav-client/blob/master/README.md Sends a ping request to the ClamAV daemon. The method returns normally if a response is received, otherwise, a ClamavException is thrown. ```java void ping(); ``` -------------------------------- ### Shutdown ClamAV Daemon Source: https://github.com/cdarras/clamav-client/blob/master/README.md Immediately shuts down the ClamAV daemon process. ```java void shutdownServer(); ``` -------------------------------- ### Reload ClamAV Virus Databases Source: https://github.com/cdarras/clamav-client/blob/master/README.md Triggers the ClamAV daemon to reload its virus definition databases. ```java void reloadVirusDatabases(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.