'Unable to create the stream to read the data from file. - Symantec Protection Engine
I am facing an issue while integration Symantec protection engine Java API. Getting an error stating as follows. This issue is with the streamScanReq.scanFile() method.
com.symantec.scanengine.api.ScanException: Unable to create the stream to read the data from file.
at com.symantec.scanengine.api.StreamScanRequestImpl.scanFile(Unknown Source)
at test.spe.VirusScan.performVirusScan(VirusScan.java:82)
at test.spe.SpePoc.main(SpePoc.java:27)
Also, getting error in streamScanReq.finish() method.
java.lang.NullPointerException at
com.symantec.scanengine.api.RequestImpl.finish(Unknown Source)
public static Result performVirusScan(InputStream inputStream, FileOutputStream outputStream, String fileName) throws IOException, ScanException
{
File file = new File("C:\\Test\\test.txt");
Vector<ScanEngineInfo> scanEnginesForScanning = new Vector<>();
ScanEngineInfo scanEngTobeUsed = new ScanEngineInfo(SCAN_ENGINE_HOST, SCAN_ENGINE_PORT);
scanEnginesForScanning.add(scanEngTobeUsed);
ScanEngine scanEngine = ScanEngine.createScanEngine(scanEnginesForScanning);
//StreamScanRequest streamScanReq = scanEngine.createStreamScanRequest(fileName, null, outputStream, Policy.SCAN);
StreamScanRequest streamScanReq = scanEngine.createStreamScanRequest(fileName, null, outputStream, Policy.SCAN, true);
FileScanRequest fileScanReq = scanEngine.createFileScanRequest("C:\\Test\\test.txt", Policy.SCAN, true);
byte[] buff = new byte[512];
long bytesToRead = file.length();
int buffCapRead = buff.length;
int bytesRead = 0;
do
{
if (bytesToRead >= buffCapRead)
{
buffCapRead = buff.length;
}
else
{
buffCapRead = (int) bytesToRead;
}
// Refresh data buffer.
buff = new byte[buffCapRead];
bytesRead = inputStream.read(buff, 0, buffCapRead);
// Send the bytes to Symantec Protection Engine
streamScanReq.send(buff);
bytesToRead = bytesToRead - bytesRead;
} while (bytesToRead > 0);
if (inputStream != null){
inputStream.close();
}
inputStream.close();
outputStream.flush();
Result result = fileScanReq.scanFile();
if(streamScanReq!= null) {
}
Result result1 = streamScanReq.scanFile();
outputStream.close();
return result1;
}
Above is the code i am using.
Please help in finding out a solution.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
