DirectoryListing getPartialListing(String src, INode targetNode,
      byte[] startAfter,
      boolean needLocation) throws IOException {
    readLock();
    try {
      if (targetNode == null)
        return null;

      if (!targetNode.isDirectory()) {
        HdfsFileStatus[] partialListing = new HdfsFileStatus[]{
            createHdfsFileStatus(
                HdfsFileStatus.EMPTY_NAME, targetNode)};
        if (needLocation) {
          return new LocatedDirectoryListing(partialListing,
              new LocatedBlocks[] {createLocatedBlocks(targetNode)}, 0);
        } else {
          return new DirectoryListing(partialListing, 0);
        }
      }
      INodeDirectory dirInode = (INodeDirectory)targetNode;
      List<INode> contents = dirInode.getChildren();
      // find the first child whose name is greater than startAfter
      int startChild = dirInode.nextChild(startAfter);
      int totalNumChildren = contents.size();
      int numOfListing = Math.min(totalNumChildren-startChild, this.lsLimit);
      HdfsFileStatus listing[] = new HdfsFileStatus[numOfListing];
      LocatedBlocks [] blockLocations = new LocatedBlocks[numOfListing];
      for (int i=0; i<numOfListing; i++) {
        INode cur = contents.get(startChild+i);
        listing[i] = createHdfsFileStatus(cur.name, cur);
        if (needLocation) {
          blockLocations[i] = createLocatedBlocks(cur);
        }
      }
      if (needLocation) {
        return new LocatedDirectoryListing(
            listing, blockLocations, totalNumChildren-startChild-numOfListing);
      } else {
        return new DirectoryListing(
            listing, totalNumChildren-startChild-numOfListing);
      }
  } finally {
    readUnlock();
  }
  }
DirectoryListing getPartialListing ( String src , INode targetNode , byte [ ] startAfter , boolean needLocation ) throws IOException { readLock ( ) ; try { if ( targetNode == null ) return null ; if ( ! targetNode . isDirectory ( ) ) { HdfsFileStatus [ ] partialListing = new HdfsFileStatus [ ] { createHdfsFileStatus ( HdfsFileStatus . EMPTY_NAME , targetNode ) } ; if ( needLocation ) { return new LocatedDirectoryListing ( partialListing , new LocatedBlocks [ ] { createLocatedBlocks ( targetNode ) } , 0 ) ; } else { return new DirectoryListing ( partialListing , 0 ) ; } } INodeDirectory dirInode = ( INodeDirectory ) targetNode ; List < INode > contents = dirInode . getChildren ( ) ; int startChild = dirInode . nextChild ( startAfter ) ; int totalNumChildren = contents . size ( ) ; int numOfListing = Math . min ( totalNumChildren - startChild , this . lsLimit ) ; HdfsFileStatus listing [ ] = new HdfsFileStatus [ numOfListing ] ; LocatedBlocks [ ] blockLocations = new LocatedBlocks [ numOfListing ] ; for ( int i = 0 ; i < numOfListing ; i ++ ) { INode cur = contents . get ( startChild + i ) ; listing [ i ] = createHdfsFileStatus ( cur . name , cur ) ; if ( needLocation ) { blockLocations [ i ] = createLocatedBlocks ( cur ) ; } } if ( needLocation ) { return new LocatedDirectoryListing ( listing , blockLocations , totalNumChildren - startChild - numOfListing ) ; } else { return new DirectoryListing ( listing , totalNumChildren - startChild - numOfListing ) ; } } finally { readUnlock ( ) ; } }
Get a partial listing of the indicated directory

@param src the directory name
@param targetNode the inode representing the given path
@param startAfter the name to start listing after
@param needLocation if block locations are returned
@return a partial listing starting after startAfter