public RemoteIterator < LocatedBlockFileStatus > listLocatedBlockStatus ( final Path f , final PathFilter filter ) throws FileNotFoundException , IOException { return new RemoteIterator < LocatedBlockFileStatus > ( ) { private final FileStatus [ ] stats ; private int i = 0 ; { // initializer stats = listStatus ( f , filter ) ; if ( stats == null ) { throw new FileNotFoundException ( "File " + f + " does not exist." ) ; } } @ Override public boolean hasNext ( ) { return i < stats . length ; } @ Override public LocatedBlockFileStatus next ( ) throws IOException { if ( ! hasNext ( ) ) { throw new NoSuchElementException ( "No more entry in " + f ) ; } FileStatus result = stats [ i ++ ] ; BlockAndLocation [ ] locs = null ; if ( ! result . isDir ( ) ) { String [ ] name = { "localhost:50010" } ; String [ ] host = { "localhost" } ; // create a dummy blockandlocation locs = new BlockAndLocation [ ] { new BlockAndLocation ( 0L , 0L , name , host , new String [ 0 ] , 0 , result . getLen ( ) , false ) } ; } return new LocatedBlockFileStatus ( result , locs , false ) ; } } ; }
Listing a directory The returned results include its blocks and locations if it is a file The results are filtered by the given path filter