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);
}