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.example.filter;
018
019import java.io.File;
020
021import org.apache.commons.vfs2.FileFilterSelector;
022import org.apache.commons.vfs2.FileObject;
023import org.apache.commons.vfs2.FileSystemManager;
024import org.apache.commons.vfs2.VFS;
025import org.apache.commons.vfs2.filter.CanReadFileFilter;
026
027/**
028 * Example for using {@link CanReadFileFilter}.
029 */
030// CHECKSTYLE:OFF Example code
031public final class CanReadFileFilterExample {
032    /**
033     * Invokes this example from the command line.
034     *
035     * @param args Arguments TODO
036     * @throws Exception If anything goes wrong.
037     */
038    public static void main(final String[] args) throws Exception {
039        final FileSystemManager fsManager = VFS.getManager();
040        final FileObject dir = fsManager.toFileObject(new File("."));
041
042        // Example, showing how to print out a list of the current directory's
043        // readable files:
044        System.out.println("---CAN_READ---");
045        for (final FileObject file : dir.findFiles(new FileFilterSelector(CanReadFileFilter.CAN_READ))) {
046            System.out.println(file);
047        }
048
049        // Example, showing how to print out a list of the current directory's
050        // un-readable files:
051        System.out.println("---CANNOT_READ---");
052        for (final FileObject file : dir.findFiles(new FileFilterSelector(CanReadFileFilter.CANNOT_READ))) {
053            System.out.println(file);
054        }
055
056        // Example, showing how to print out a list of the current directory's
057        // read-only files:
058        System.out.println("---READ_ONLY---");
059        for (final FileObject file : dir.findFiles(new FileFilterSelector(CanReadFileFilter.READ_ONLY))) {
060            System.out.println(file);
061        }
062
063    }
064
065    private CanReadFileFilterExample() {
066        /* main class not instantiated. */
067    }
068
069}
070// CHECKSTYLE:ON