Example usage for org.apache.hadoop.fs AbstractFileSystem getFileBlockLocations

List of usage examples for org.apache.hadoop.fs AbstractFileSystem getFileBlockLocations

Introduction

In this page you can find the example usage for org.apache.hadoop.fs AbstractFileSystem getFileBlockLocations.

Prototype

public abstract BlockLocation[] getFileBlockLocations(final Path f, final long start, final long len)
        throws AccessControlException, FileNotFoundException, UnresolvedLinkException, IOException;

Source Link

Document

The specification of this method matches that of FileContext#getFileBlockLocations(Path,long,long) except that Path f must be for this file system.

Usage

From source file:com.cloudera.impala.catalog.TestLoadHdfsMetadataPerf.java

License:Apache License

/**
 * List file status by calling abstractFileSystem.listStatusIterator.
 *///from  w w  w  . ja  v  a 2 s  .c  o  m
private static void listStatusIterator(String dirPath) {
    Path path = new Path(dirPath);
    boolean exceptionThrown = false;
    try {
        AbstractFileSystem fs = AbstractFileSystem.createFileSystem(path.toUri(), LoadMetadataUtil.getConf());
        RemoteIterator<FileStatus> iter = fs.listStatusIterator(path);
        while (iter.hasNext()) {
            FileStatus fileStatus = iter.next();
            BlockLocation[] locations = fs.getFileBlockLocations(fileStatus.getPath(), 0, fileStatus.getLen());
            for (BlockLocation loc : locations) {
                loc.getNames();
                loc.getHosts();
            }
        }
    } catch (IOException e) {
        exceptionThrown = true;
        LOG.error("Failed to list Status Iterator", e);
    }
    assertFalse(exceptionThrown);
}