Example usage for org.apache.hadoop.fs FileContext listStatus

List of usage examples for org.apache.hadoop.fs FileContext listStatus

Introduction

In this page you can find the example usage for org.apache.hadoop.fs FileContext listStatus.

Prototype

public RemoteIterator<FileStatus> listStatus(final Path f)
        throws AccessControlException, FileNotFoundException, UnsupportedFileSystemException, IOException 

Source Link

Document

List the statuses of the files/directories in the given path if the path is a directory.

Usage

From source file:co.cask.cdap.common.io.Locations.java

License:Apache License

/**
 * Returns {@link RemoteIterator} of {@link LocationStatus} under a directory
 * represented by the given {@link Location}.
 *///from  w  w  w  . j  av  a  2  s. c o m
private static RemoteIterator<LocationStatus> listLocationStatus(Location location) throws IOException {
    LocationFactory lf = location.getLocationFactory();
    if (lf instanceof HDFSLocationFactory) {
        FileStatus[] fileStatuses = ((HDFSLocationFactory) lf).getFileSystem()
                .listStatus(new Path(location.toURI()));
        return transform(asRemoteIterator(Iterators.forArray(fileStatuses)), FILE_STATUS_TO_LOCATION_STATUS);
    }
    if (lf instanceof FileContextLocationFactory) {
        FileContext fc = ((FileContextLocationFactory) lf).getFileContext();
        return transform(fc.listStatus(new Path(location.toURI())), FILE_STATUS_TO_LOCATION_STATUS);
    }
    return transform(asRemoteIterator(location.list().iterator()), LOCATION_TO_LOCATION_STATUS);
}

From source file:com.ikanow.aleph2.aleph2_rest_utils.DataStoreCrudService.java

License:Apache License

private static Collection<FileDescriptor> getFolderFilenames(final String folder,
        final FileContext file_context) throws AccessControlException, FileNotFoundException,
        UnsupportedFileSystemException, IllegalArgumentException, IOException {
    Collection<FileDescriptor> file_names = new ArrayList<FileDescriptor>();
    RemoteIterator<FileStatus> file_status = file_context.listStatus(new Path(folder));
    while (file_status.hasNext())
        file_names.add(new FileDescriptor(null, file_status.next().getPath().getName()));
    return file_names;
}