Stream Virus Scanner

Hi, There:

Not much too exciting going on for a while. However, today I did some virus scanning process using Symantec Virus Scanner Engine API. The goal is to streaming huge data binary into Symantec Engine for scanning without busting memory.  It is not fancy but thing working pretty well for a few hundred MB of binary, with decent performance. Due to the streaming, the size limit will be the configured memory upper limit of the Scan Engine itself.

I am outlining the steps here with some example code. Hope it helps.

  • Prepare Scan Engine with Policy (default shown)
ScanEngine.ScanEngineInfo scanEngTobeUsed = new ScanEngine.ScanEngineInfo("virusscanhost",1344);
Vector <ScanEngine.ScanEngineInfo> scanEnginesForScanning = new Vector <ScanEngine.ScanEngineInfo>();
ScanEngine scanEngine = ScanEngine.createScanEngine(scanEnginesForScanning);
ByteArrayOutputStream bao = new ByteArrayOutputStream();
StreamScanRequest scanRequest = scanEngine.createStreamScanRequest("", null, bao, Policy.DEFAULT);
  • Streaming binary data into buffer while sending to the Scan Engine
byte[] b = new byte[4096];
while ( // more binary streaming in ... ) {
   b = ....; // get more binary here into buffer
  • Finish and examine the Scan Result
Result result = scanRequest.finish();
// read or examine result here

That’s all and cheers!