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

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

Introduction

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

Prototype

public boolean isAbsolute() 

Source Link

Document

Returns true if the path component (i.e.

Usage

From source file:com.asakusafw.windgate.hadoopfs.HadoopFsMirror.java

License:Apache License

private List<Path> resolvePaths(ProcessScript<?> proc, DriverScript.Kind kind, String pathString)
        throws IOException {
    assert proc != null;
    assert kind != null;
    assert pathString != null;
    Path basePath = profile.getBasePath();
    String[] paths = pathString.split("[ \t\r\n]+");
    List<Path> results = new ArrayList<>();
    for (String path : paths) {
        if (path.isEmpty()) {
            continue;
        }//from  ww w . j av a2  s.  c o  m
        String resolved;
        try {
            resolved = arguments.replace(path, true);
        } catch (IllegalArgumentException e) {
            WGLOG.error(e, "E01001", getName(), proc.getName(), kind.prefix, FILE.key(), pathString);
            throw new IOException(
                    MessageFormat.format("Failed to resolve the {2} path: {3} (resource={0}, process={1})",
                            getName(), proc.getName(), kind.toString(), path));
        }
        Path relative = new Path(resolved);
        if (relative.isAbsolute()) {
            WGLOG.warn("W01001", getName(), proc.getName(), kind.prefix, FILE.key(), pathString);
        }
        results.add(new Path(basePath, relative));
    }
    return results;
}

From source file:com.bigstep.datalake.DLFileSystem.java

License:Apache License

private Path makeAbsolute(Path f) {
    return f.isAbsolute() ? f : new Path(workingDir, f);
}

From source file:com.ceph.rados.fs.hdfs.RadosFileSystem.java

License:Apache License

private Path makeAbsolute(Path path) {
    if (path.isAbsolute()) {
        return path;
    }/*from www. j a  va 2 s .c  om*/
    return new Path(workingDir, path);
}

From source file:com.ceph.rados.fs.RadosFileSystemStore.java

License:Apache License

private String pathToKey(Path path) {
    if (!path.isAbsolute()) {
        throw new IllegalArgumentException("Path must be absolute: " + path);
    }/*  ww  w.  j  a  v a  2 s . c om*/
    return path.toUri().getPath();
}

From source file:com.cloudera.cdk.data.filesystem.FileSystemView.java

License:Apache License

private static boolean cleanlyDelete(FileSystem fs, Path root, Path dir) {
    try {//w w  w .j av a  2 s  . c om
        boolean deleted = false;
        if (dir.isAbsolute()) {
            deleted = fs.delete(dir, true /* include any files */ );
        } else {
            // the path should be treated as relative to the root path
            Path absolute = new Path(root, dir);
            deleted = fs.delete(absolute, true /* include any files */ );
            // iterate up to the root, removing empty directories
            for (Path current = absolute.getParent(); !current.equals(root)
                    && !current.isRoot(); current = current.getParent()) {
                final FileStatus[] stats = fs.listStatus(current);
                if (stats == null || stats.length == 0) {
                    // dir is empty and should be removed
                    deleted = fs.delete(current, true) || deleted;
                } else {
                    // all parent directories will be non-empty
                    break;
                }
            }
        }
        return deleted;
    } catch (IOException ex) {
        throw new DatasetIOException("Could not cleanly delete path:" + dir, ex);
    }
}

From source file:com.datatorrent.contrib.hdht.HDHTFileAccessFSImpl.java

License:Open Source License

@Override
public void rename(long bucketKey, String fromName, String toName) throws IOException {
    FileContext fc = FileContext.getFileContext(fs.getUri());
    Path bucketPath = getBucketPath(bucketKey);
    // file context requires absolute path
    if (!bucketPath.isAbsolute()) {
        bucketPath = new Path(fs.getWorkingDirectory(), bucketPath);
    }//from ww w  . j  a va  2 s.co  m
    fc.rename(new Path(bucketPath, fromName), new Path(bucketPath, toName), Rename.OVERWRITE);
}

From source file:com.facebook.presto.hive.PrestoS3FileSystem.java

License:Apache License

private static String keyFromPath(Path path) {
    checkArgument(path.isAbsolute(), "Path is not absolute: %s", path);
    String key = nullToEmpty(path.toUri().getPath());
    if (key.startsWith("/")) {
        key = key.substring(1);//from  ww  w.ja v  a2 s  . co  m
    }
    if (key.endsWith("/")) {
        key = key.substring(0, key.length() - 1);
    }
    return key;
}

From source file:com.facebook.presto.hive.s3.PrestoS3FileSystem.java

License:Apache License

private static String keyFromPath(Path path) {
    checkArgument(path.isAbsolute(), "Path is not absolute: %s", path);
    String key = nullToEmpty(path.toUri().getPath());
    if (key.startsWith(PATH_SEPARATOR)) {
        key = key.substring(PATH_SEPARATOR.length());
    }//from   w  w w .  j a v a  2s .com
    if (key.endsWith(PATH_SEPARATOR)) {
        key = key.substring(0, key.length() - PATH_SEPARATOR.length());
    }
    return key;
}

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

License:Open Source License

/**
 * Translates a "gs:/" style hadoopPath (or relative path which is not fully-qualified) into
 * the appropriate GCS path which is compatible with the underlying GcsFs or gsutil.
 *///from w  w  w  . ja va  2  s  .c om
@Override
public URI getGcsPath(Path hadoopPath) {
    LOG.debug("GHFS.getGcsPath: {}", hadoopPath);

    // Convert to fully qualified absolute path; the Path object will callback to get our current
    // workingDirectory as part of fully resolving the path.
    Path resolvedPath = makeQualified(hadoopPath);

    String objectName = resolvedPath.toUri().getPath();
    if (objectName != null && resolvedPath.isAbsolute()) {
        // Strip off leading '/' because GoogleCloudStorageFileSystem.getPath appends it explicitly
        // between bucket and objectName.
        objectName = objectName.substring(1);
    }

    // Construct GCS path uri.
    URI gcsPath = gcsfs.getPathCodec().getPath(rootBucket, objectName, true);
    LOG.debug("GHFS.getGcsPath: {} -> {}", hadoopPath, gcsPath);
    return gcsPath;
}

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

License:Open Source License

/**
 *
 * <p> Overridden to make root it's own parent. This is POSIX compliant, but more importantly
 * guards against poor directory accounting in the PathData class of Hadoop 2's FsShell.
 *///from  ww  w.  ja  va2 s  .c  o  m
@Override
public Path makeQualified(Path path) {
    LOG.debug("GHFS.makeQualified: path: {}", path);
    Path qualifiedPath = super.makeQualified(path);

    URI uri = qualifiedPath.toUri();

    Preconditions.checkState("".equals(uri.getPath()) || qualifiedPath.isAbsolute(),
            "Path '%s' must be fully qualified.", qualifiedPath);

    // Strip initial '..'s to make root is its own parent.
    StringBuilder sb = new StringBuilder(uri.getPath());
    while (sb.indexOf("/../") == 0) {
        // Leave a preceding slash, so path is still absolute.
        sb.delete(0, 3);
    }

    String strippedPath = sb.toString();

    // Allow a Path of gs://someBucket to map to gs://someBucket/
    if (strippedPath.equals("/..") || strippedPath.equals("")) {
        strippedPath = "/";
    }

    Path result = new Path(uri.getScheme(), uri.getAuthority(), strippedPath);
    LOG.debug("GHFS.makeQualified:=> {}", result);
    return result;
}