実装のガイドライン
ファイルボルトシステムでウィルススキャナーフックをカスタマイズするには、以下のインタフェースの実装を参照してください。
* 
以下の実装は、インタフェースの実装を作成する際に役立つ参照としてのみ提供されています。すべてのカスタマイズは、推奨されるコーディングの最良事例およびその他の顧客固有の考慮事項に従う必要があります。
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;
}
}
これは役に立ちましたか?