public DirStatus filterAndTruncateDirStatus(String nameFilter, int maxAllowedSize, FileStatus[] fileStatuses) {
    if(null == fileStatuses){
      return new DirStatus(null, new DirListInfo(0, false, 0, nameFilter));
    }

    int originalSize = fileStatuses.length;
    boolean truncated = false;

    if (!Strings.isNullOrEmpty(nameFilter)) {
      List<FileStatus> filteredList = new LinkedList<>();
      for(FileStatus fileStatus : fileStatuses){
        if(maxAllowedSize >=0 && maxAllowedSize <= filteredList.size()){
          truncated = true;
          break;
        }
        if(fileStatus.getPath().getName().contains(nameFilter)){
          filteredList.add(fileStatus);
        }
      }
      fileStatuses = filteredList.toArray(new FileStatus[0]);
    }

    if(maxAllowedSize >=0 && fileStatuses.length > maxAllowedSize) { // in cases where name filter loop is not executed.
      truncated = true;
      fileStatuses = Arrays.copyOf(fileStatuses, maxAllowedSize);
    }

    int finalSize = fileStatuses.length;

    return new DirStatus(fileStatuses, new DirListInfo(originalSize, truncated, finalSize, nameFilter));
  }
@param path : list files and dirs in this path
@param nameFilter : if not empty or null, then file names that contain this are only sent.
@param maxAllowedSize : maximum number of files sent in output. -1 means infinite.
@return
@throws FileNotFoundException
@throws IOException
@throws InterruptedException
contrib/views/utils/src/main/java/org/apache/ambari/view/utils/hdfs/HdfsApi.java