Example usage for org.apache.hadoop.fs FileSystem getLinkTarget

List of usage examples for org.apache.hadoop.fs FileSystem getLinkTarget

Introduction

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

Prototype

public Path getLinkTarget(Path f) throws IOException 

Source Link

Document

See FileContext#getLinkTarget(Path) .

Usage

From source file:com.mellanox.r4h.DistributedFileSystem.java

License:Apache License

@Override
public Path getLinkTarget(final Path f)
        throws AccessControlException, FileNotFoundException, UnsupportedFileSystemException, IOException {
    statistics.incrementReadOps(1);/*  w  w w  .j  a  v  a 2 s  . c o m*/
    final Path absF = fixRelativePart(f);
    return new FileSystemLinkResolver<Path>() {
        @Override
        public Path doCall(final Path p) throws IOException, UnresolvedLinkException {
            HdfsFileStatus fi = dfs.getFileLinkInfo(getPathName(p));
            if (fi != null) {
                return fi.makeQualified(getUri(), p).getSymlink();
            } else {
                throw new FileNotFoundException("File does not exist: " + p);
            }
        }

        @Override
        public Path next(final FileSystem fs, final Path p) throws IOException, UnresolvedLinkException {
            return fs.getLinkTarget(p);
        }
    }.resolve(this, absF);
}

From source file:fr.ens.biologie.genomique.eoulsan.data.protocols.PathDataProtocol.java

License:LGPL

@Override
public boolean exists(final DataFile src, final boolean followLink) {

    final Path path = getPath(src);

    try {// w w  w . j  a va2  s.co  m

        final FileSystem fs = path.getFileSystem(conf);

        final FileStatus status = fs.getFileStatus(path);

        if (status == null) {
            return false;
        }

        if (status.isSymlink()) {

            return fs.getFileStatus(fs.getLinkTarget(path)) != null;
        }

        return true;
    } catch (IOException e) {
        return false;
    }
}

From source file:org.kitesdk.data.spi.filesystem.FileSystemUtil.java

License:Apache License

private static <T> T visit(PathVisitor<T> visitor, FileSystem fs, Path path, List<Path> followedLinks)
        throws IOException {
    if (fs.isFile(path)) {
        return visitor.file(fs, path);
    } else if (IS_SYMLINK != null && IS_SYMLINK.<Boolean>invoke(fs.getFileStatus(path))) {
        Preconditions.checkArgument(!followedLinks.contains(path),
                "Encountered recursive path structure at link: " + path);
        followedLinks.add(path); // no need to remove
        return visit(visitor, fs, fs.getLinkTarget(path), followedLinks);
    }/* w w w .java2s  .  co m*/

    List<T> children = Lists.newArrayList();

    FileStatus[] statuses = fs.listStatus(path, PathFilters.notHidden());
    for (FileStatus stat : statuses) {
        children.add(visit(visitor, fs, stat.getPath()));
    }

    return visitor.directory(fs, path, children);
}