001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.vfs2.filter;
018
019import java.io.Serializable;
020
021import org.apache.commons.vfs2.FileFilter;
022import org.apache.commons.vfs2.FileSelectInfo;
023import org.apache.commons.vfs2.FileSystemException;
024import org.apache.commons.vfs2.FileType;
025
026/**
027 * This filter accepts {@code File}s that are files (not directories).
028 * <p>
029 * For example, here is how to print out a list of the real files within the
030 * current directory:
031 * </p>
032 *
033 * <pre>
034 * FileSystemManager fsManager = VFS.getManager();
035 * FileObject dir = fsManager.toFileObject(new File(&quot;.&quot;));
036 * FileObject[] files = dir.findFiles(new FileFilterSelector(FileFileFilter.FILE));
037 * for (int i = 0; i &lt; files.length; i++) {
038 *     System.out.println(files[i]);
039 * }
040 * </pre>
041 *
042 * @author This code was originally ported from Apache Commons IO File Filter
043 * @see "https://commons.apache.org/proper/commons-io/"
044 * @since 2.4
045 */
046public class FileFileFilter implements FileFilter, Serializable {
047
048    /** Singleton instance of file filter. */
049    public static final FileFilter FILE = new FileFileFilter();
050
051    private static final long serialVersionUID = 1L;
052
053    /**
054     * Restrictive constructor.
055     */
056    protected FileFileFilter() {
057    }
058
059    /**
060     * Checks to see if the file is a file.
061     *
062     * @param fileSelectInfo the File to check
063     * @return true if the file is a file
064     * @throws FileSystemException Thrown for file system errors.
065     */
066    @Override
067    public boolean accept(final FileSelectInfo fileSelectInfo) throws FileSystemException {
068        return fileSelectInfo.getFile().getType() == FileType.FILE;
069    }
070
071}