Example usage for org.apache.hadoop.fs FileStatus FileStatus

List of usage examples for org.apache.hadoop.fs FileStatus FileStatus

Introduction

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

Prototype

public FileStatus(long length, boolean isdir, int block_replication, long blocksize, long modification_time,
        long access_time, FsPermission permission, String owner, String group, Path path) 

Source Link

Document

Constructor for file systems on which symbolic links are not supported

Usage

From source file:alluxio.hadoop.AbstractFileSystem.java

License:Apache License

/**
 * {@inheritDoc}//from   w w  w.  ja  v  a  2s.c o  m
 *
 * If the file does not exist in Alluxio, query it from HDFS.
 */
@Override
public FileStatus getFileStatus(Path path) throws IOException {
    LOG.info("getFileStatus({})", path);

    if (mStatistics != null) {
        mStatistics.incrementReadOps(1);
    }
    AlluxioURI uri = new AlluxioURI(HadoopUtils.getPathWithoutScheme(path));
    URIStatus fileStatus;
    try {
        fileStatus = sFileSystem.getStatus(uri);
    } catch (FileDoesNotExistException e) {
        throw new FileNotFoundException(e.getMessage());
    } catch (AlluxioException e) {
        throw new IOException(e);
    }

    return new FileStatus(fileStatus.getLength(), fileStatus.isFolder(), BLOCK_REPLICATION_CONSTANT,
            fileStatus.getBlockSizeBytes(), fileStatus.getCreationTimeMs(), fileStatus.getCreationTimeMs(),
            new FsPermission((short) fileStatus.getMode()), fileStatus.getOwner(), fileStatus.getGroup(),
            new Path(mAlluxioHeader + uri));
}

From source file:alluxio.hadoop.AbstractFileSystem.java

License:Apache License

@Override
public FileStatus[] listStatus(Path path) throws IOException {
    LOG.info("listStatus({})", path);

    if (mStatistics != null) {
        mStatistics.incrementReadOps(1);
    }/*from   w w w  .  j  av a 2s . c  o  m*/

    AlluxioURI uri = new AlluxioURI(HadoopUtils.getPathWithoutScheme(path));
    List<URIStatus> statuses;
    try {
        statuses = sFileSystem.listStatus(uri);
    } catch (FileDoesNotExistException e) {
        throw new FileNotFoundException(HadoopUtils.getPathWithoutScheme(path));
    } catch (AlluxioException e) {
        throw new IOException(e);
    }

    FileStatus[] ret = new FileStatus[statuses.size()];
    for (int k = 0; k < statuses.size(); k++) {
        URIStatus status = statuses.get(k);
        // TODO(hy): Replicate 3 with the number of disk replications.
        ret[k] = new FileStatus(status.getLength(), status.isFolder(), 3, status.getBlockSizeBytes(),
                status.getCreationTimeMs(), status.getCreationTimeMs(), null, null, null,
                new Path(mAlluxioHeader + status.getPath()));
    }
    return ret;
}

From source file:com.asakusafw.windgate.hadoopfs.ssh.FileList.java

License:Apache License

/**
 * Creates a simple {@link FileStatus}./*from www. ja  va 2 s  . co  m*/
 * @param path the target path
 * @return the created file status with the specified path
 * @throws IllegalArgumentException if some parameters were {@code null}
 * @deprecated should not use this
 */
@Deprecated
public static FileStatus createFileStatus(Path path) {
    if (path == null) {
        throw new IllegalArgumentException("path must not be null"); //$NON-NLS-1$
    }
    return new FileStatus(0, false, 0, 0, 0, 0, null, null, null, path);
}

From source file:com.cloudera.hoop.client.fs.HoopFileSystem.java

License:Open Source License

/**
 * Creates a <code>FileStatus</code> object using a JSON file-status payload
 * received from a Hoop server./*from  w  ww .  ja v  a 2  s  .  c o  m*/
 *
 * @param json a JSON file-status payload received from a Hoop server
 * @return the corresponding <code>FileStatus</code>
 */
private FileStatus createFileStatus(JSONObject json) {
    Path path = new Path((String) json.get("path"));
    boolean isDir = (Boolean) json.get("isDir");
    long len = (Long) json.get("len");
    String owner = (String) json.get("owner");
    String group = (String) json.get("group");
    FsPermission permission = FsPermission.valueOf((String) json.get("permission"));
    long aTime = (Long) json.get("accessTime");
    long mTime = (Long) json.get("modificationTime");
    long blockSize = (Long) json.get("blockSize");
    short replication = (short) (long) (Long) json.get("replication");
    return new FileStatus(len, isDir, replication, blockSize, mTime, aTime, permission, owner, group, path);
}

From source file:com.google.cloud.hadoop.fs.gcs.GoogleHadoopFileSystemBase.java

License:Open Source License

/**
 * Gets FileStatus corresponding to the given FileInfo value.
 *///from w  ww .j av  a  2  s  . c  o m
private FileStatus getFileStatus(FileInfo fileInfo) {
    // GCS does not provide modification time. It only provides creation time.
    // It works for objects because they are immutable once created.
    FileStatus status = new FileStatus(fileInfo.getSize(), fileInfo.isDirectory(), REPLICATION_FACTOR_DEFAULT,
            defaultBlockSize, fileInfo.getModificationTime(), /* Last modification time */
            fileInfo.getModificationTime(), /* Last access time */
            reportedPermissions, USER_NAME, USER_NAME, getHadoopPath(fileInfo.getPath()));
    LOG.debug("GHFS.getFileStatus: {} => {}", fileInfo.getPath(), fileStatusToString(status));
    return status;
}

From source file:com.ibm.crail.hdfs.CrailHadoopFileSystem.java

License:Apache License

@Override
public FileStatus[] listStatus(Path path) throws FileNotFoundException, IOException {
    try {//from   w w w .j  a  v a 2s .  c  om
        CrailNode node = dfs.lookup(path.toUri().getRawPath()).get();
        Iterator<String> iter = node.getType() == CrailNodeType.DIRECTORY ? node.asDirectory().listEntries()
                : node.asMultiFile().listEntries();
        ArrayList<FileStatus> statusList = new ArrayList<FileStatus>();
        while (iter.hasNext()) {
            String filepath = iter.next();
            CrailNode directFile = dfs.lookup(filepath).get();
            if (directFile != null) {
                FsPermission permission = FsPermission.getFileDefault();
                if (directFile.getType().isDirectory()) {
                    permission = FsPermission.getDirDefault();
                }
                FileStatus status = new FileStatus(directFile.getCapacity(), directFile.getType().isContainer(),
                        CrailConstants.SHADOW_REPLICATION, CrailConstants.BLOCK_SIZE,
                        directFile.getModificationTime(), directFile.getModificationTime(), permission,
                        CrailConstants.USER, CrailConstants.USER,
                        new Path(filepath).makeQualified(this.getUri(), this.workingDir));
                statusList.add(status);
            }
        }
        FileStatus[] list = new FileStatus[statusList.size()];
        statusList.toArray(list);
        return list;
    } catch (Exception e) {
        throw new FileNotFoundException(path.toUri().getRawPath());
    }
}

From source file:com.ibm.crail.hdfs.CrailHadoopFileSystem.java

License:Apache License

@Override
public FileStatus getFileStatus(Path path) throws IOException {
    CrailNode directFile = null;/*ww  w  .jav a  2  s.co  m*/
    try {
        directFile = dfs.lookup(path.toUri().getRawPath()).get();
    } catch (Exception e) {
        throw new IOException(e);
    }
    if (directFile == null) {
        throw new FileNotFoundException("File does not exist: " + path);
    }
    FsPermission permission = FsPermission.getFileDefault();
    if (directFile.getType().isDirectory()) {
        permission = FsPermission.getDirDefault();
    }
    FileStatus status = new FileStatus(directFile.getCapacity(), directFile.getType().isContainer(),
            CrailConstants.SHADOW_REPLICATION, CrailConstants.BLOCK_SIZE, directFile.getModificationTime(),
            directFile.getModificationTime(), permission, CrailConstants.USER, CrailConstants.USER,
            path.makeQualified(this.getUri(), this.workingDir));
    return status;
}

From source file:com.ibm.crail.hdfs.CrailHDFS.java

License:Apache License

@Override
public FileStatus getFileStatus(Path path)
        throws AccessControlException, FileNotFoundException, UnresolvedLinkException, IOException {
    CrailNode directFile = null;//w ww.  j  a  v  a 2  s.  c o  m
    try {
        directFile = dfs.lookup(path.toUri().getRawPath()).get();
    } catch (Exception e) {
        throw new IOException(e);
    }
    if (directFile == null) {
        throw new FileNotFoundException("filename " + path);
    }

    FsPermission permission = FsPermission.getFileDefault();
    if (directFile.getType().isDirectory()) {
        permission = FsPermission.getDirDefault();
    }
    FileStatus status = new FileStatus(directFile.getCapacity(), directFile.getType().isContainer(),
            CrailConstants.SHADOW_REPLICATION, CrailConstants.BLOCK_SIZE, directFile.getModificationTime(),
            directFile.getModificationTime(), permission, CrailConstants.USER, CrailConstants.USER,
            path.makeQualified(this.getUri(), this.workingDir));
    return status;
}

From source file:com.ibm.crail.hdfs.CrailHDFS.java

License:Apache License

@Override
public FileStatus[] listStatus(Path path)
        throws AccessControlException, FileNotFoundException, UnresolvedLinkException, IOException {
    try {/*  ww  w  . j a  v a2s . c om*/
        CrailNode node = dfs.lookup(path.toUri().getRawPath()).get();
        Iterator<String> iter = node.getType() == CrailNodeType.DIRECTORY ? node.asDirectory().listEntries()
                : node.asMultiFile().listEntries();
        ArrayList<FileStatus> statusList = new ArrayList<FileStatus>();
        while (iter.hasNext()) {
            String filepath = iter.next();
            CrailNode directFile = dfs.lookup(filepath).get();
            if (directFile != null) {
                FsPermission permission = FsPermission.getFileDefault();
                if (directFile.getType().isDirectory()) {
                    permission = FsPermission.getDirDefault();
                }
                FileStatus status = new FileStatus(directFile.getCapacity(), directFile.getType().isContainer(),
                        CrailConstants.SHADOW_REPLICATION, CrailConstants.BLOCK_SIZE,
                        directFile.getModificationTime(), directFile.getModificationTime(), permission,
                        CrailConstants.USER, CrailConstants.USER,
                        new Path(filepath).makeQualified(this.getUri(), workingDir));
                statusList.add(status);
            }
        }
        FileStatus[] list = new FileStatus[statusList.size()];
        statusList.toArray(list);
        return list;
    } catch (Exception e) {
        throw new FileNotFoundException(path.toUri().getRawPath());
    }
}

From source file:com.ibm.stocator.fs.swift.SwiftAPIClient.java

License:Open Source License

/**
 * Maps StoredObject of JOSS into Hadoop FileStatus
 *
 * @param tmp//from ww w.  ja  v  a2  s . c  om
 * @param cObj
 * @param hostName
 * @param path
 * @return FileStatus representing current object
 * @throws IllegalArgumentException
 * @throws IOException
 */
private FileStatus getFileStatus(StoredObject tmp, Container cObj, String hostName, Path path)
        throws IllegalArgumentException, IOException {
    String newMergedPath = getMergedPath(hostName, path, tmp.getName());
    return new FileStatus(tmp.getContentLength(), false, 1, blockSize, getLastModified(tmp.getLastModified()),
            0, null, null, null, new Path(newMergedPath));
}