Package org.primefaces.virusscan.impl
Class ClamDaemonClient
- java.lang.Object
-
- org.primefaces.virusscan.impl.ClamDaemonClient
-
public class ClamDaemonClient extends Object
Simple client for ClamAV's clamd scanner. Provides straightforward instream scanning. Support for basic INSTREAM scanning and PING command. Clamd protocol is explained here:
-
-
Constructor Summary
Constructors Constructor Description ClamDaemonClient(String hostName, int port)
ClamDaemonClient(String hostName, int port, int timeout, int chunkSize)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Socket
getSocket()
Get a socket to the current host and port.static boolean
isCleanReply(byte[] reply)
Interpret the result from a ClamAV scan, and determine if the result means the data is clean.boolean
ping()
Run PING command to CLAMD to test it is responding.byte[]
scan(byte[] in)
Scans bytes for virus by passing the bytes to clamavbyte[]
scan(InputStream is)
Streams the given data to the server in chunks.
-
-
-
Constructor Detail
-
ClamDaemonClient
public ClamDaemonClient(String hostName, int port, int timeout, int chunkSize)
- Parameters:
hostName
- The hostname of the server running clamav-daemonport
- The port that clamav-daemon listens to(By default it might not listen to a port. Check your clamav configuration).timeout
- zero means infinite timeout. Not a good idea, but will be accepted.
-
ClamDaemonClient
public ClamDaemonClient(String hostName, int port)
-
-
Method Detail
-
ping
public boolean ping() throws IOException
Run PING command to CLAMD to test it is responding.- Returns:
- true if the server responded with proper ping reply.
- Throws:
IOException
- if there is an I/O problem communicating with CLAMD
-
scan
public byte[] scan(InputStream is) throws IOException
Streams the given data to the server in chunks. The whole data is not kept in memory. This method is preferred if you don't want to keep the data in memory, for instance by scanning a file on disk. Since the parameter InputStream is not reset, you can not use the stream afterwards, as it will be left in a EOF-state. If your goal is to scan some data, and then pass that data further, consider usingscan(byte[] in)
.Opens a socket and reads the reply. Parameter input stream is NOT closed.
- Parameters:
is
- data to scan. Not closed by this method!- Returns:
- server reply
- Throws:
IOException
- if there is an I/O problem
-
scan
public byte[] scan(byte[] in) throws IOException
Scans bytes for virus by passing the bytes to clamav- Parameters:
in
- data to scan.- Returns:
- server reply
- Throws:
IOException
- if there is an I/O problem
-
getSocket
protected Socket getSocket() throws IOException
Get a socket to the current host and port. Partly implemented as a separate method for unit testing purposes.- Returns:
- socket to host and port
- Throws:
IOException
- if an I/O error occurs when creating the socket
-
isCleanReply
public static boolean isCleanReply(byte[] reply)
Interpret the result from a ClamAV scan, and determine if the result means the data is clean.- Parameters:
reply
- The reply from the server after scanning- Returns:
- true if no virus was found according to the clamd reply message
-
-