code: public static BlockAndLocation[] locatedBlocks2BlockLocations(
       LocatedBlocks blocks) {
     if (blocks == null) {
       return new BlockAndLocation[0];
     }
     int nrBlocks = blocks.locatedBlockCount();
     BlockAndLocation[] blkLocations = new BlockAndLocation[nrBlocks];
     if (nrBlocks == 0) {
       return blkLocations;
     }
     int idx = 0;
     for (LocatedBlock blk : blocks.getLocatedBlocks()) {
       assert idx < nrBlocks : "Incorrect index";
       DatanodeInfo[] locations = blk.getLocations();
       String[] hosts = new String[locations.length];
       String[] names = new String[locations.length];
       String[] racks = new String[locations.length];
       for (int hCnt = 0; hCnt < locations.length; hCnt++) {
         hosts[hCnt] = locations[hCnt].getHostName();
         names[hCnt] = locations[hCnt].getName();
         NodeBase node = new NodeBase(names[hCnt],
                                      locations[hCnt].getNetworkLocation());
         racks[hCnt] = node.toString();
       }
       Block block = blk.getBlock();
       blkLocations[idx] = new BlockAndLocation(block.getBlockId(),
                                             block.getGenerationStamp(),
                                             names, hosts, racks,
                                             blk.getStartOffset(),
                                             block.getNumBytes(),
                                             blk.isCorrupt());
       idx++;
     }
     return blkLocations;
   }
docs: Convert a LocatedBlocks to BlockAndLocations[]
  @param blocks a LocatedBlocks
  @return an array of BlockLocations