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 @Override
030 public boolean isActive() {
031 return _ACTIVE;
032 }
033
034 @Override
035 public void scan(byte[] bytes) throws AntivirusScannerException {
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 @Override
056 public void scan(InputStream inputStream) throws AntivirusScannerException {
057 File file = null;
058
059 try {
060 file = FileUtil.createTempFile(_ANTIVIRUS_EXTENSION);
061
062 FileUtil.write(file, inputStream);
063
064 scan(file);
065 }
066 catch (IOException ioe) {
067 throw new SystemException("Unable to write temporary file", ioe);
068 }
069 finally {
070 if (file != null) {
071 file.delete();
072 }
073 }
074 }
075
076 private static final boolean _ACTIVE = true;
077
078 private static final String _ANTIVIRUS_EXTENSION = "avs";
079
080 }