import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.lang.management.ThreadInfo; import java.util.Vector; import com.symantec.scanengine.api.FileScanRequest; import com.symantec.scanengine.api.Policy; import com.symantec.scanengine.api.Result; import com.symantec.scanengine.api.ScanEngine; import com.symantec.scanengine.api.ScanException; import com.symantec.scanengine.api.StreamScanRequest; import com.symantec.scanengine.api.ThreatInfo; public class main { static String fileForScan = ""; static String serverIP = "192.168.80.20"; static int serverPort = 1344; static Vector scanEnginesForScanning = new Vector(); //To scan the file is able to use more that one Symantec server. static Policy scPolicy = Policy.DEFAULT; //By default Symantec only scan the file. /** * @param args */ public static void main(String[] args) { if(args.length==0){ System.out.print("Set as first parameter full path to file which you would like to scan."); return; } else { fileForScan=args[0].trim(); } long time = System.currentTimeMillis(); //To measure the duration of the test ScanEngine.ScanEngineInfo scanEngTobeUsed = new ScanEngine.ScanEngineInfo(serverIP,serverPort); //set IP and port of Symantec server scanEnginesForScanning.add(scanEngTobeUsed); Result result=null; try { //File will be streamed int cnt =0; byte[] buff = new byte[512]; File fp = new File(fileForScan); FileOutputStream output; output = new FileOutputStream(fileForScan+"SCANNED"); //Scanned and repaired file will be saved in this file. ScanEngine scanEngine = ScanEngine.createScanEngine(scanEnginesForScanning); FileInputStream fin = new FileInputStream(fileForScan); StreamScanRequest streamScanReq = scanEngine.createStreamScanRequest(fileForScan, fileForScan, output, scPolicy); long bytesToRead = fp.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 = fin.read(buff, 0, buffCapRead); // Send the bytes to scan engine streamScanReq.send(buff); bytesToRead = bytesToRead - bytesRead; } while (bytesToRead > 0); fin.close(); result = streamScanReq.finish(); } catch (Exception e) { e.printStackTrace(); } time = System.currentTimeMillis()-time; //To measure the duration of the test System.out.println("Scanned file: "+ fileForScan); System.out.println("Status: "+result.getStatus()); System.out.println("Count of infections: "+result.getTotalInfection()); ThreatInfo threatInfo[] = result.getThreatInfo(); for(int i=0; iThread category: "+threatInfo[i].getThreatCategory()); System.out.println(">Disposition: "+threatInfo[i].getDisposition()); System.out.println(">Violation ID: "+threatInfo[i].getViolationId()); System.out.println(">Violation name: "+threatInfo[i].getViolationName()); } System.out.println("Duration of the test: "+time/1000+" s"); } }