Example usage for org.apache.hadoop.fs Path toUri

List of usage examples for org.apache.hadoop.fs Path toUri

Introduction

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

Prototype

public URI toUri() 

Source Link

Document

Convert this Path to a URI.

Usage

From source file:com.quantcast.qfs.hadoop.QFSEmulationImpl.java

License:Apache License

public FileStatus[] readdirplus(Path path) throws IOException {
    return localFS.listStatus(new Path(path.toUri().getPath()));
}

From source file:com.quantcast.qfs.hadoop.QFSEmulationImpl.java

License:Apache License

public FileStatus stat(Path path) throws IOException {
    return localFS.getFileStatus(new Path(path.toUri().getPath()));
}

From source file:com.quantcast.qfs.hadoop.QFSEmulationImpl.java

License:Apache License

public KfsFileAttr fullStat(Path path) throws IOException {
    FileStatus fs = localFS.getFileStatus(new Path(path.toUri().getPath()));
    KfsFileAttr fa = new KfsFileAttr();
    fa.filename = fs.getPath().toUri().getPath();
    fa.isDirectory = fs.isDir();/*from w ww .ja  v  a  2s.  c  o m*/
    fa.filesize = fs.getLen();
    fa.replication = fs.getReplication();
    fa.modificationTime = fs.getModificationTime();
    return fa;
}

From source file:com.quantcast.qfs.hadoop.QFSImpl.java

License:Apache License

public FileStatus[] readdirplus(Path path) throws IOException {
    KfsAccess.DirectoryIterator itr = null;
    try {// w w w  . j a  v a  2  s  . c om
        itr = kfsAccess.new DirectoryIterator(path.toUri().getPath());
        final ArrayList<FileStatus> ret = new ArrayList<FileStatus>();
        String prefix = path.toString();
        if (!prefix.endsWith("/")) {
            prefix += "/";
        }
        while (itr.next()) {
            if (itr.filename.compareTo(".") == 0 || itr.filename.compareTo("..") == 0) {
                continue;
            }
            ret.add(new FileStatus(itr.isDirectory ? 0L : itr.filesize, itr.isDirectory,
                    itr.isDirectory ? 1 : itr.replication, itr.isDirectory ? 0 : BLOCK_SIZE,
                    itr.modificationTime, ACCESS_TIME, FsPermission.createImmutable((short) itr.mode),
                    itr.ownerName, itr.groupName, new Path(prefix + itr.filename)));
        }
        return ret.toArray(new FileStatus[0]);
    } finally {
        if (itr != null) {
            itr.close();
        }
    }
}

From source file:com.quantcast.qfs.hadoop.QFSImpl.java

License:Apache License

public FileStatus stat(Path path) throws IOException {
    final KfsFileAttr fa = new KfsFileAttr();
    final String pn = path.toUri().getPath();
    kfsAccess.kfs_retToIOException(kfsAccess.kfs_stat(pn, fa), pn);
    return new FileStatus(fa.isDirectory ? 0L : fa.filesize, fa.isDirectory,
            fa.isDirectory ? 1 : fa.replication, fa.isDirectory ? 0 : BLOCK_SIZE, fa.modificationTime,
            ACCESS_TIME, FsPermission.createImmutable((short) fa.mode), fa.ownerName, fa.groupName, path);
}

From source file:com.quantcast.qfs.hadoop.QFSImpl.java

License:Apache License

public KfsFileAttr fullStat(Path path) throws IOException {
    final KfsFileAttr fa = new KfsFileAttr();
    final String pn = path.toUri().getPath();
    kfsAccess.kfs_retToIOException(kfsAccess.kfs_stat(pn, fa), pn);
    return fa;/*from  w w  w .j a v a2  s .  c  om*/
}

From source file:com.quantcast.qfs.hadoop.QuantcastFileSystem.java

License:Apache License

@Deprecated
public boolean isDirectory(Path path) throws IOException {
    Path absolute = makeAbsolute(path);
    String srep = absolute.toUri().getPath();
    return qfsImpl.isDirectory(srep);
}

From source file:com.quantcast.qfs.hadoop.QuantcastFileSystem.java

License:Apache License

@Deprecated
public boolean isFile(Path path) throws IOException {
    Path absolute = makeAbsolute(path);
    String srep = absolute.toUri().getPath();
    return qfsImpl.isFile(srep);
}

From source file:com.quantcast.qfs.hadoop.QuantcastFileSystem.java

License:Apache License

public boolean rename(Path src, Path dst) throws IOException {
    Path absoluteS = makeAbsolute(src);
    String srepS = absoluteS.toUri().getPath();
    Path absoluteD = makeAbsolute(dst);
    String srepD = absoluteD.toUri().getPath();

    return qfsImpl.rename(srepS, srepD) == 0;
}

From source file:com.quantcast.qfs.hadoop.QuantcastFileSystem.java

License:Apache License

public boolean delete(Path path, boolean recursive) throws IOException {
    final Path absolute = makeAbsolute(path);
    try {/*from w ww  .  j a  va  2 s  . c  o  m*/
        final KfsFileAttr fa = qfsImpl.fullStat(absolute);
        final String srep = absolute.toUri().getPath();
        if (!fa.isDirectory) {
            return qfsImpl.remove(srep) == 0;
        }
        if (recursive) {
            return qfsImpl.rmdirs(srep) == 0;
        }
        boolean notEmptyFlag = fa.fileCount > 0 || fa.dirCount > 0;
        if (!notEmptyFlag && (fa.fileCount < 0 || fa.dirCount < 0)) {
            // Backward compatibility: handle the case if sub counts are not
            // available.
            final FileStatus[] dirEntries = qfsImpl.readdirplus(absolute);
            notEmptyFlag = dirEntries != null && dirEntries.length > 0;
        }
        if (notEmptyFlag) {
            throw new IOException("Directory " + path.toString() + " is not empty.");
        }
        return qfsImpl.rmdir(srep) == 0;
    } catch (FileNotFoundException e) {
        return false;
    }
}