List the given path iteratively if the directory is large

@param src a path
@return a listing of the path
@throws IOException if any IO error is occurred
437478
private FileStatus[] iterativeListing(String src) throws IOException {
    // fetch the first batch of entries in the directory
    DirectoryListing thisListing = namenode.getPartialListing(
        src, HdfsFileStatus.EMPTY_NAME);

    if (thisListing == null) { // the directory does not exist
      return null;
     }
    HdfsFileStatus[] partialListing = thisListing.getPartialListing();
    if (!thisListing.hasMore()) { // got all entries of the directory
      FileStatus[] stats = new FileStatus[partialListing.length];
      for (int i = 0; i < partialListing.length; i++) {
        stats[i] = HdfsFileStatus.toFileStatus(partialListing[i], src);
      }
      return stats;
    }

    // The directory size is too big that it needs to fetch more
    // estimate the total number of entries in the directory
    int totalNumEntries =
      partialListing.length + thisListing.getRemainingEntries();
    ArrayList<FileStatus> listing =
      new ArrayList<FileStatus>(totalNumEntries);
    // add the first batch of entries to the array list
    for (HdfsFileStatus fileStatus : partialListing) {
      listing.add(HdfsFileStatus.toFileStatus(fileStatus, src));
    }

    // now fetch more entries
    do {
      thisListing = namenode.getPartialListing(src, thisListing.getLastName());

      if (thisListing == null) {
        return null; // the directory is deleted
      }

      partialListing = thisListing.getPartialListing();
      for (HdfsFileStatus fileStatus : partialListing) {
        listing.add(HdfsFileStatus.toFileStatus(fileStatus, src));
      }
    } while (thisListing.hasMore());

    return listing.toArray(new FileStatus[listing.size()]);
  }
823301
public RemoteIterator<Path> listCorruptFileBlocks(final Path path,
                                                    final boolean useStandby)
    throws IOException {
    return new StandbyCaller<RemoteIterator<Path>>() {
      @Override
      RemoteIterator<Path> call(DistributedFileSystem fs) throws IOException {
        return fs.listCorruptFileBlocks(path);
      }
    }.callFS(useStandby);
  }
303873
boolean isDir(String src) {
    byte[][] components = INodeDirectory.getPathComponents(normalizePath(src));
    readLock();
    try {
      INode node = rootDir.getNode(components);
      return isDir(node);
    } finally {
      readUnlock();
    }
  }
29253
private static List<Path> file_listing_(Path dir) throws IOException {
        try (Stream<Path> files = Files.list(dir)) {
            return files.collect(Collectors.toList());
        }
    }
138932
public long copyFileFromImpl(InputStream src) throws FileNotFoundException, CopyFileFromException {
        try (OutputStream dest = newOutputStream()) {
            return getWorld().getBuffer().copy(src, dest);
        } catch (FileNotFoundException e) {
            throw e;
        } catch (IOException e) {
            throw new CopyFileFromException(this, e);
        }
    }
311931
public List<FileInfo> getFileInfos(List<URI> paths) throws IOException {
    checkArgument(paths != null, "paths must not be null");
    logger.atFine().log("getFileInfos(%d paths)", paths.size());

    if (paths.size() == 1) {
      return new ArrayList<>(Collections.singleton(getFileInfo(paths.get(0))));
    }

    int maxThreads = gcs.getOptions().getBatchThreads();
    ExecutorService fileInfoExecutor =
        maxThreads == 0
            ? MoreExecutors.newDirectExecutorService()
            : Executors.newFixedThreadPool(
                Math.min(maxThreads, paths.size()), DAEMON_THREAD_FACTORY);
    try {
      List<Future<FileInfo>> infoFutures = new ArrayList<>(paths.size());
      for (URI path : paths) {
        infoFutures.add(fileInfoExecutor.submit(() -> getFileInfo(path)));
      }
      fileInfoExecutor.shutdown();

      List<FileInfo> infos = new ArrayList<>(paths.size());
      for (Future<FileInfo> infoFuture : infoFutures) {
        try {
          infos.add(infoFuture.get());
        } catch (InterruptedException | ExecutionException e) {
          if (e instanceof InterruptedException) {
            Thread.currentThread().interrupt();
          }
          throw new IOException(
              String.format("Failed to getFileInfos for %d paths", paths.size()), e);
        }
      }
      return infos;
    } finally {
      fileInfoExecutor.shutdownNow();
    }
  }
916352
int getFileCrc(String src) throws IOException {
    checkOpen();
    return getFileCrc(dataTransferVersion,
        src, namenode, namenodeProtocolProxy, socketFactory, socketTimeout);
  }
550755
public Path download(URI src) {
    try {
      return paths.get(src);
    } catch (ExecutionException e) {
      throw new RuntimeException(e);
    }
  }
1166632
public static ArrayList<File> getFilesInDirectoryTree(String path) {
		File directory = new File(path);
		return getContentsInDirectoryTree(directory, "*", true, false);
	}
571129
public boolean hardLink(Path src, Path dst) throws IOException {  
    return fs.hardLink(src, dst);
  }
786070
static void move(File src, File dest) throws IOException {
        try {
            Files.move(src.toPath(), dest.toPath());
        } catch (IOException x) {
            throw x;
        } catch (Exception x) {
            throw new IOException(x);
        }
    }
489384
private static byte[] readFrom(File src) throws IOException {
        long srcsize = src.length();
        if (srcsize > Integer.MAX_VALUE) {
            throw new IllegalArgumentException(
                    "File too big to be loaded in memory");
        }
        FileInputStream inputStream = new FileInputStream(src);
        byte[] array = new byte[(int) srcsize];
        try {
            FileChannel fileChannel = inputStream.getChannel();
            ByteBuffer byteBuffer = ByteBuffer.wrap(array);
            int read = 0;
            while (read < srcsize) {
                read += fileChannel.read(byteBuffer);
            }
        } finally {
            inputStream.close();
        }
        return array;
    }
969404
public DirectoryListing getPartialListing(String src, byte[] startAfter,
                                            boolean needLocation)
    throws IOException {
    DirectoryListing stats;
    src = dir.normalizePath(src);
    byte[][] names = INode.getPathComponents(src);
    INode[] inodes = new INode[names.length];
    readLock();
    try {
      dir.rootDir.getExistingPathINodes(names, inodes);
      getListingCheck(src, inodes);
      stats = dir.getPartialListing(src, inodes[inodes.length-1],
          startAfter, needLocation);
    } finally {
      readUnlock();
    }
    if (auditLog.isInfoEnabled()) {
      logAuditEvent(getCurrentUGI(),
        Server.getRemoteIp(),
        "listStatus", src, null, null);
    }
    return stats;
  }
379366
public static IoBuffer copy(ByteBuffer src) {
        IoBuffer copy = IoBuffer.allocate(src.remaining());
        copy.put(src);
        copy.flip();
        return copy;
    }
395600
public static void listStatusForLeafDir(FileSystem fs,
      FileStatus pathStatus,
      List<FileStatus> acc) throws IOException {
    if (!pathStatus.isDir())
      return;
    FileStatus[] fileStatusResults = fs.listStatus(pathStatus.getPath());
    if (fileStatusResults == null) {
      throw new IOException("Path does not exist: " + pathStatus.getPath());
    }

    boolean leafDir = true;
    for (FileStatus f : fileStatusResults) {
      if (f.isDir()) {
        leafDir = false;
        listStatusForLeafDir(fs, f, acc);
      }
    }
    if (leafDir) {
      acc.add(pathStatus); // Accumulate leaf dir
    }
  }
177084
public long getHardLinkId(String src) throws IOException {
    byte[][] components = INode.getPathComponents(src);
    readLock();
    try {
      INodeFile node = this.getFileINode(components);
      if ((!exists(node)) || (!(node instanceof INodeHardLinkFile))) {
        throw new IOException(src + " is not a valid hardlink file");
      }
      return ((INodeHardLinkFile) node).getHardLinkID();
    } finally {
      readUnlock();
    }
  }
800443
public static File[] ls(String path) {
		if (path == null) {
			return null;
		}

		path = getAbsolutePath(path);

		File file = file(path);
		if (file.isDirectory()) {
			return file.listFiles();
		}
		throw new IORuntimeException(StrUtil.format("Path [{}] is not directory!", path));
	}