001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019package org.apache.hadoop.mapred;
020
021import org.apache.hadoop.classification.InterfaceAudience;
022import org.apache.hadoop.classification.InterfaceStability;
023import org.apache.hadoop.fs.Path;
024import org.apache.hadoop.fs.PathFilter;
025
026/**
027 * A utility class. It provides
028 *   A path filter utility to filter out output/part files in the output dir
029 */
030@InterfaceAudience.Public
031@InterfaceStability.Stable
032public class Utils {
033  public static class OutputFileUtils {
034    /**
035     * This class filters output(part) files from the given directory
036     * It does not accept files with filenames _logs and _SUCCESS.
037     * This can be used to list paths of output directory as follows:
038     *   Path[] fileList = FileUtil.stat2Paths(fs.listStatus(outDir,
039     *                                         new OutputFilesFilter()));
040     */
041    public static class OutputFilesFilter extends OutputLogFilter {
042      public boolean accept(Path path) {
043        return super.accept(path) 
044               && !FileOutputCommitter.SUCCEEDED_FILE_NAME
045                   .equals(path.getName());
046      }
047    }
048    
049    /**
050     * This class filters log files from directory given
051     * It doesnt accept paths having _logs.
052     * This can be used to list paths of output directory as follows:
053     *   Path[] fileList = FileUtil.stat2Paths(fs.listStatus(outDir,
054     *                                   new OutputLogFilter()));
055     */
056    public static class OutputLogFilter implements PathFilter {
057      public boolean accept(Path path) {
058        return !"_logs".equals(path.getName());
059      }
060    }
061  }
062}