public static List<FileStatus> listLocatedFileStatus(final FileSystem fs, final Path path, final PathFilter filter,
      final boolean recursive) throws IOException {
    RemoteIterator<LocatedFileStatus> itr = fs.listFiles(path, recursive);
    List<FileStatus> result = new ArrayList<>();
    while (itr.hasNext()) {
      FileStatus stat = itr.next();
      // Recursive listing might list files inside hidden directories, we need to filter those out
      if (!stat.getPath().toString().equals(path.toString())) {
        Path relativePath = new Path(stat.getPath().toString().replace(path.toString(), ""));
        if (!org.apache.hadoop.hive.metastore.utils.FileUtils.RemoteIteratorWithFilter.HIDDEN_FILES_FULL_PATH_FILTER.accept(relativePath)) {
          continue;
        }
      }
      // Apply the user provided filter
      if (filter == null || filter.accept(stat.getPath())) {
        result.add(stat);
      }

    }
    return result;
  }
List filestatuses in the given directory.
In recursive mode all files are returned, otherwise directories are skipped.
@param fs FileSystem
@param path directory to list
@param filter optional filter
@param recursive do recursive listing
@return
@throws IOException
ql/src/java/org/apache/hadoop/hive/ql/io/HdfsUtils.java