001
014
015 package com.liferay.portlet.documentlibrary.antivirus;
016
017 import com.liferay.portal.kernel.exception.SystemException;
018 import com.liferay.portal.kernel.util.FileUtil;
019
020 import java.io.File;
021 import java.io.IOException;
022 import java.io.InputStream;
023
024
027 public abstract class BaseFileAntivirusScanner implements AntivirusScanner {
028
029 public boolean isActive() {
030 return _ACTIVE;
031 }
032
033 public void scan(byte[] bytes)
034 throws AntivirusScannerException, SystemException {
035
036 File file = null;
037
038 try {
039 file = FileUtil.createTempFile(_ANTIVIRUS_EXTENSION);
040
041 FileUtil.write(file, bytes);
042
043 scan(file);
044 }
045 catch (IOException ioe) {
046 throw new SystemException("Unable to write temporary file", ioe);
047 }
048 finally {
049 if (file != null) {
050 file.delete();
051 }
052 }
053 }
054
055 public void scan(InputStream inputStream)
056 throws AntivirusScannerException, SystemException {
057
058 File file = null;
059
060 try {
061 file = FileUtil.createTempFile(_ANTIVIRUS_EXTENSION);
062
063 FileUtil.write(file, inputStream);
064
065 scan(file);
066 }
067 catch (IOException ioe) {
068 throw new SystemException("Unable to write temporary file", ioe);
069 }
070 finally {
071 if (file != null) {
072 file.delete();
073 }
074 }
075 }
076
077 private static final boolean _ACTIVE = true;
078
079 private static final String _ANTIVIRUS_EXTENSION = "avs";
080
081 }