Web uygulamasına dosya yüklerken Symantec Scan Engine’in Java API’si ile virüs taraması yapabilirsiniz. Örnek virüs tarayıcı Java sınıfı şu şekildedir:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
public class VirusScanner { private final Policy scanPolicy; private final String scanEngineIp; private final int scanEnginePort; private VectorscanEngines; private ScanEngine.ScanEngineInfo scanEngineToUser; private ScanEngine scanEngine; public VirusScanner(final Policy scanPolicy, final String scanEngineIp, final int scanEnginePort) { super(); this.scanPolicy = scanPolicy; this.scanEngineIp = scanEngineIp; this.scanEnginePort = scanEnginePort; } public void init() throws ScanException { this.scanEngines = new Vector(); this.scanEngineToUser = new ScanEngine.ScanEngineInfo(this.scanEngineIp, this.scanEnginePort); this.scanEngines.add(this.scanEngineToUser); this.scanEngine = ScanEngine.createScanEngine(this.scanEngines); } public Result scanFile(final File file) throws ScanException, IOException { final File virusScanOutputFile = File.createTempFile("scanresult", ".tmp"); final FileOutputStream output = FileUtils.openOutputStream(virusScanOutputFile); final FileInputStream virusScanInputStream = FileUtils.openInputStream(file); Result result = null; byte[] buffer = new byte[512]; final StreamScanRequest streamScanRequest = this.scanEngine.createStreamScanRequest(file.getAbsolutePath(), file.getName(), output, this.scanPolicy); long bytesToRead = file.length(); int buffCapRead = buffer.length; int bytesRead = 0; do { if (bytesToRead == buffCapRead) { buffCapRead = buffer.length; } else { buffCapRead = (int) bytesToRead; } // Refresh data buffer. buffer = new byte[buffCapRead]; bytesRead = virusScanInputStream.read(buffer, 0, buffCapRead); // Send the bytes to scan engine streamScanRequest.send(buffer); bytesToRead = bytesToRead - bytesRead; } while (bytesToRead, 0); virusScanInputStream.close(); result = streamScanRequest.finish(); output.close(); return result; } } |
Kullanmak için VirusScanner sınıfını initialize edip scanFile(File file) metoduna java.io.File sınıfını parametre olarak geçmeniz yeterlidir. Result olarak da Result.CLEAN sonucunu aldığınızda yüklediğiniz dosya virüssüz demektir. Symantec Scan Engine’in 30 günlik trial versiyonunu indirip içinden çıkan JAR’ı projenize eklediğinizde yukarıdaki sınıfları kullanabilirsiniz. (http://www.symantec.com/scan-engine) Detaylı bilgi için: ftp://ftp.symantec.com/public/english_us_canada/products/symantec_scan_engine/5.1/manuals/GettingStarted.pdf