001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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            @Override
032            public boolean isActive() {
033                    return _ACTIVE;
034            }
035    
036            @Override
037            public void scan(File file)
038                    throws AntivirusScannerException, SystemException {
039    
040                    InputStream inputStream = null;
041    
042                    try {
043                            inputStream = new FileInputStream(file);
044    
045                            scan(inputStream);
046                    }
047                    catch (FileNotFoundException fnfe) {
048                            throw new SystemException("Unable to scan file", fnfe);
049                    }
050                    finally {
051                            StreamUtil.cleanUp(inputStream);
052                    }
053            }
054    
055            private static final boolean _ACTIVE = true;
056    
057    }