001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.documentlibrary.antivirus;
016    
017    import com.liferay.portal.kernel.exception.SystemException;
018    import com.liferay.portal.kernel.util.StreamUtil;
019    
020    import java.io.File;
021    import java.io.FileInputStream;
022    import java.io.FileNotFoundException;
023    import java.io.InputStream;
024    
025    /**
026     * @author Michael C. Han
027     */
028    public abstract class BaseInputStreamAntivirusScanner
029            implements AntivirusScanner {
030    
031            public boolean isActive() {
032                    return _ACTIVE;
033            }
034    
035            public void scan(File file)
036                    throws AntivirusScannerException, SystemException {
037    
038                    InputStream inputStream = null;
039    
040                    try {
041                            inputStream = new FileInputStream(file);
042    
043                            scan(inputStream);
044                    }
045                    catch (FileNotFoundException fnfe) {
046                            throw new SystemException("Unable to scan file", fnfe);
047                    }
048                    finally {
049                            StreamUtil.cleanUp(inputStream);
050                    }
051            }
052    
053            private static boolean _ACTIVE = true;
054    
055    }