Implementation Guidelines
Refer to the following implementation of interface to customize the virus scanner hook in your File Vault system:
* 
The following implementation is provided only for reference to assist in creating the implementation for interface.All customization should follow recommended coding best practices and other customer specific considerations.
package wt.content;
import java.io.*;
import java.util.*;
import xyz.capybara.clamav.ClamavClient;
import xyz.capybara.clamav.commands.scan.result.ScanResult;
/**
* Sample implementation of IContentProcessor interface for Virus Scanning of content
*/
public class ClamAVContentProcessor implements IContentProcessor {
public ProcessResult processPreStore(InputStream inputStream, Map <String, Object> data) throws WTException {
byte[] buffer = new byte[1024];
int len;
ProcessResult processResult = new ProcessResult();
try {
//read content and store in byte array
long length = 0;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while ((len = inputStream.read(buffer))> -1)
{
baos.write(buffer, 0, len);
length += len;
}
baos.flush();
//WARNING: After reading data from inputStream, do not close inputStream.
//construct InputStream to pass it to Anti-Virus Software
byte[] bytes = baos.toByteArray();
InputStream is1 = new ByteArrayInputStream(bytes);
//create client to connect securely to Anti-Virus Software of your choice
ClamavClient clamavClient = new ClamavClient("127.0.0.1");
//scan the content for virus
String operation = (String)data.get(IContentProcessor.OPERATION_KEY);
String vaultFileName = (String)data.get(IContentProcessor.FILE_NAME_KEY);
long fileSize = (Long)data.get(IContentProcessor.FILE_SIZE_KEY);
System.out.println("scanning content for operation = "+operation+", to be stored in vault as "+vaultFileName);
ScanResult scanResult = clamavClient.scan(is1);
System.out.println("scanResult = "+scanResult);
//if virus found, reject the content
if(scanResult instanceof ScanResult.VirusFound) {
throw new WTException("Virus found during scan = "+scanResult);
}
//if virus not found, return the content and content length to Content Service
InputStream is2 = new ByteArrayInputStream(bytes);
processResult.setInputStream(is2);
processResult.setLength(length);
}catch (IOException e) {
throw new WTException(e);
}
return processResult;
}
}
War dies hilfreich?