下面列出了org.apache.hadoop.fs.Path#isAbsolute ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Convert Hadoop path into IGFS path.
*
* @param path Hadoop path.
* @return IGFS path.
*/
@Nullable private IgfsPath convert(Path path) {
if (path == null)
return null;
return path.isAbsolute() ? new IgfsPath(path.toUri().getPath()) :
new IgfsPath(workingDir, path.toUri().getPath());
}
/**
* Make an absolute path relative by stripping the leading /
*/
static Path makeRelative(Path path) {
if (!path.isAbsolute()) {
return path;
}
String p = path.toUri().getPath();
String relative = p.substring(1, p.length());
return new Path(relative);
}
/**
* @param path
* @return full path including the chroot
*/
protected Path fullPath(final Path path) {
super.checkPath(path);
return path.isAbsolute() ?
new Path((chRootPathPart.isRoot() ? "" : chRootPathPartString)
+ path.toUri().getPath()) :
new Path(chRootPathPartString + workingDir.toUri().getPath(), path);
}
public final void symlink(Path src, Path dst) throws IOException {
if (!src.isAbsolute()) {
throw new IOException("Source must be absolute");
}
if (dst.isAbsolute()) {
throw new IOException("Destination must be relative");
}
if (dst.toUri().getPath().indexOf('/') != -1) {
mkdir(dst.getParent());
}
link(src, dst);
}
/**
* Converts Hadoop path to local path.
*
* @param path Hadoop path.
* @return Local path.
*/
File convert(Path path) {
checkPath(path);
if (path.isAbsolute())
return new File(path.toUri().getPath());
return new File(getWorkingDirectory().toUri().getPath(), path.toUri().getPath());
}
/**
* Get the absolute version of the path (fully qualified).
* This is public for testing purposes.
*
* @param path
* @return fully qualified path
*/
@VisibleForTesting
public Path makeAbsolute(Path path) {
if (path.isAbsolute()) {
return path;
}
return new Path(workingDir, path);
}
/**
* Makes path absolute
*
* @param path path to file
* @return absolute path
*/
protected Path makeAbsolute(Path path) {
if (path.isAbsolute()) {
return path;
}
return new Path(workingDir, path);
}
/**
* Get the absolute version of the path (fully qualified).
* This is public for testing purposes.
*
* @param path
* @return fully qualified path
*/
@VisibleForTesting
public Path makeAbsolute(Path path) {
if (path.isAbsolute()) {
return path;
}
return new Path(workingDir, path);
}
@Override
public Path getAbsoluteTestRootPath(FileSystem fSys) {
Path testRootPath = new Path(TEST_ROOT_DIR);
if (testRootPath.isAbsolute()) {
return testRootPath;
} else {
return new Path(fSys.getWorkingDirectory(), TEST_ROOT_DIR);
}
}
private static String pathToKey(Path path) {
if (path.toUri().getScheme() != null && path.toUri().getPath().isEmpty()) {
// allow uris without trailing slash after bucket to refer to root,
// like s3n://mybucket
return "";
}
if (!path.isAbsolute()) {
throw new IllegalArgumentException("Path must be absolute: " + path);
}
String ret = path.toUri().getPath().substring(1); // remove initial slash
if (ret.endsWith("/") && (ret.indexOf("/") != ret.length() - 1)) {
ret = ret.substring(0, ret.length() -1);
}
return ret;
}
public String getMetastoreBigCellHdfsDirectory() {
if (cachedBigCellDirectory != null)
return cachedBigCellDirectory;
String root = getOptional("kylin.env.hdfs-metastore-bigcell-dir");
if (root == null) {
return getJdbcHdfsWorkingDirectory();
}
Path path = new Path(root);
if (!path.isAbsolute())
throw new IllegalArgumentException(
"kylin.env.hdfs-metastore-bigcell-dir must be absolute, but got " + root);
// make sure path is qualified
try {
FileSystem fs = HadoopUtil.getReadFileSystem();
path = fs.makeQualified(path);
} catch (IOException e) {
throw new RuntimeException(e);
}
root = new Path(path, StringUtils.replaceChars(getMetadataUrlPrefix(), ':', '-')).toString();
if (!root.endsWith("/"))
root += "/";
cachedBigCellDirectory = root;
if (cachedBigCellDirectory.startsWith(FILE_SCHEME)) {
cachedBigCellDirectory = cachedBigCellDirectory.replace(FILE_SCHEME, "file://");
} else if (cachedBigCellDirectory.startsWith(MAPRFS_SCHEME)) {
cachedBigCellDirectory = cachedBigCellDirectory.replace(MAPRFS_SCHEME, "maprfs://");
}
return cachedBigCellDirectory;
}
/**
* @param path
* @return full path including the chroot
*/
protected Path fullPath(final Path path) {
super.checkPath(path);
return path.isAbsolute() ?
new Path((chRootPathPart.isRoot() ? "" : chRootPathPartString)
+ path.toUri().getPath()) :
new Path(chRootPathPartString + workingDir.toUri().getPath(), path);
}
/**
* Construct the absolute path from the file location and the current
* directory. The current directory is either of the form
* {code}hdfs://<nodename>:<nodeport>/<directory>{code} in Hadoop
* MapReduce mode, or of the form
* {code}file:///<directory>{code} in Hadoop local mode.
*
* @param location the location string specified in the load statement
* @param curDir the current file system directory
* @return the absolute path of file in the file system
* @throws FrontendException if the scheme of the location is incompatible
* with the scheme of the file system
*/
public static String getAbsolutePath(String location, Path curDir)
throws FrontendException {
if (location == null || curDir == null) {
throw new FrontendException(
"location: " + location + " curDir: " + curDir);
}
URI fsUri = curDir.toUri();
String fsScheme = fsUri.getScheme();
if (fsScheme == null) {
throw new FrontendException("curDir: " + curDir);
}
fsScheme = fsScheme.toLowerCase();
String authority = fsUri.getAuthority();
if(authority == null) {
authority = "";
}
Path rootDir = new Path(fsScheme, authority, "/");
ArrayList<String> pathStrings = new ArrayList<String>();
String[] fnames = getPathStrings(location);
for (String fname: fnames) {
// remove leading/trailing whitespace(s)
fname = fname.trim();
Path p = new Path(fname);
URI uri = p.toUri();
// if the supplied location has a scheme (i.e. uri is absolute) or
// an absolute path, just use it.
if(! (uri.isAbsolute() || p.isAbsolute())) {
String scheme = uri.getScheme();
if (scheme != null) {
scheme = scheme.toLowerCase();
}
if (scheme != null && !scheme.equals(fsScheme)) {
throw new FrontendException("Incompatible file URI scheme: "
+ scheme + " : " + fsScheme);
}
String path = uri.getPath();
fname = (p.isAbsolute()) ?
new Path(rootDir, path).toString() :
new Path(curDir, path).toString();
}
fname = fname.replaceFirst("^file:/([^/])", "file:///$1");
// remove the trailing /
fname = fname.replaceFirst("/$", "");
pathStrings.add(fname);
}
return join(pathStrings, ",");
}
private static String pathToKey(Path path) {
if (!path.isAbsolute()) {
throw new IllegalArgumentException("Path must be absolute: " + path);
}
return path.toUri().getPath().substring(1); // remove initial slash
}
private static String pathToKey(Path path) {
if (!path.isAbsolute()) {
throw new IllegalArgumentException("Path must be absolute: " + path);
}
return path.toUri().getPath().substring(1); // remove initial slash
}
private String pathToKey(Path path) {
if (!path.isAbsolute()) {
throw new IllegalArgumentException("Path must be absolute: " + path);
}
return path.toUri().getPath();
}
private Path makeAbsolute(Path path) {
if (path.isAbsolute()) {
return path;
}
return new Path(workingDir, path);
}
private Path makeAbsolute(Path path) {
if (path.isAbsolute()) {
return path;
}
return new Path(workingDir, path);
}
private Path makeAbsolute(Path path) {
if (path.isAbsolute()) {
return path;
}
return new Path(workingDir, path);
}
private String pathToKey(Path path) {
if (!path.isAbsolute()) {
throw new IllegalArgumentException("Path must be absolute: " + path);
}
return urlEncode(path.toUri().getPath());
}