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; 024 025/** 026 * This filter accepts {@code File}s that can be executed. 027 * <p> 028 * Example, showing how to print out a list of the current directory's 029 * <em>executable</em> files: 030 * </p> 031 * 032 * <pre> 033 * FileSystemManager fsManager = VFS.getManager(); 034 * FileObject dir = fsManager.toFileObject(new File(".")); 035 * FileObject[] files = dir.findFiles(new FileFilterSelector(CanReadFileFilter.CAN_EXECUTE)); 036 * for (int i = 0; i < files.length; i++) { 037 * System.out.println(files[i]); 038 * } 039 * </pre> 040 * 041 * <p> 042 * Example, showing how to print out a list of the current directory's 043 * <em>un-executable</em> files: 044 * </p> 045 * 046 * <pre> 047 * FileSystemManager fsManager = VFS.getManager(); 048 * FileObject dir = fsManager.toFileObject(new File(".")); 049 * FileObject[] files = dir.findFiles(new FileFilterSelector(CanReadFileFilter.CANNOT_EXECUTE)); 050 * for (int i = 0; i < files.length; i++) { 051 * System.out.println(files[i]); 052 * } 053 * </pre> 054 * 055 * @see "https://commons.apache.org/proper/commons-io/" 056 * @since 2.4 057 */ 058public class CanExecuteFileFilter implements FileFilter, Serializable { 059 060 /** Singleton instance of <em>executed</em> filter. */ 061 public static final FileFilter CAN_EXECUTE = new CanExecuteFileFilter(); 062 063 /** Singleton instance of not <em>executed</em> filter. */ 064 public static final FileFilter CANNOT_EXECUTE = new NotFileFilter(CAN_EXECUTE); 065 066 private static final long serialVersionUID = 1L; 067 068 /** 069 * Restrictive constructor. 070 */ 071 protected CanExecuteFileFilter() { 072 } 073 074 /** 075 * Checks to see if the file can be executed. 076 * 077 * @param fileSelectInfo the File to check. 078 * @return {@code true} if the file can be executed, otherwise {@code false}. 079 * @throws FileSystemException Thrown for file system errors. 080 */ 081 @Override 082 public boolean accept(final FileSelectInfo fileSelectInfo) throws FileSystemException { 083 return fileSelectInfo.getFile().isExecutable(); 084 } 085 086}