Hi Davis,
we have set the default size in the scan engine. we have not changed anything in the default settings. The code.
PFB the code we are using to communcate to java engine. the code is failing for the input data tha have 1060522 bytes. Can you please advice , what should be done.
byte[] binaryData = AttachmentData;
String SCAN_OUTPUT_FILE_NAME =FileOutput;
String scanEngineHost = scanEngineHostName;
int scanEnginePort=scanEnginePortNumber;
Policy scPolicy= Policy.SCANDELETE;
ScanEngine scanEngine=null;
Vector scanEnginesForScanning = null;
FileOutputStream output = null;
FileInputStream fileInputStream = null;
File file = null;
byte[] buffer = new byte[4096];
StringBuffer outputFileName = null;
Long myTimeStamp;
myTimeStamp = System.currentTimeMillis();
outputFileName = new StringBuffer(SCAN_OUTPUT_FILE_NAME);
ScanEngine.ScanEngineInfo scanEngTobeUsed = new ScanEngine.ScanEngineInfo(scanEngineHost,scanEnginePort);
scanEnginesForScanning = new Vector();
scanEnginesForScanning.add(scanEngTobeUsed);
scanEngine = ScanEngine.createScanEngine(scanEnginesForScanning);
output = new FileOutputStream(outputFileName.toString());
StreamScanRequest streamScanRequest = null;
streamScanRequest = scanEngine.createStreamScanRequest("",null,output,scPolicy);
// Send the data to the scanning engine
ByteArrayInputStream BinaryData=new ByteArrayInputStream(binaryData);
long fileLength = BinaryData.available();
long bytesToRead = fileLength;
int buffCapRead = buffer.length;
long bytesRead = 0;
int i =1;
FileLength=fileLength;
// Read the input file and send the data to the scanning engine
do {
// System.out.println("Iteration :"+i);
if (bytesToRead >= buffCapRead)
{
buffCapRead = buffer.length;
}
else
{
buffCapRead = (int) bytesToRead;
}
// Refresh data buffer.
buffer = new byte[buffCapRead];
bytesRead = BinaryData.read(buffer, 0, buffCapRead);
// Send the bytes to scan engine
streamScanRequest.send(buffer);
bytesToRead = bytesToRead - bytesRead;
i=i+1;
} while (bytesToRead > 0);
if(fileLength >0)
{
// Getting the result of the scanning for virus
Thread.sleep(50000);
Result result = streamScanRequest.finish();
//Check if the Scan is complete and the result is clean. Return true.
if((result != null && result.getStatus().compareTo(ResultStatus.CLEAN)==0))
{
virusFlag = true;
}
else
{
if(result == null || result.getStatus().compareTo(ResultStatus.INFECTED_REPLACED)==0 ||
result.getStatus().compareTo(ResultStatus.INFECTED_UNREPAIRED)==0)
{
virusFlag = false;
}
else{
//System.out.println("Could not Scan");
}
}
}
output.close();
File myOutputFile = new File(outputFileName.toString());
myOutputFile.delete();
}
catch (ScanException e)
{
StringWriter sw = new StringWriter();
new Throwable(e).printStackTrace(new PrintWriter(sw));
ErrorStack = sw.toString();
ErrorMessage = e.getMessage();
}
catch (Exception g)
{
StringWriter sw = new StringWriter();
new Throwable(g).printStackTrace(new PrintWriter(sw));
ErrorStack = sw.toString();
ErrorMessage = g.getMessage();
}
//return virusFlag;
}
}