/** * Given a {@link Path} path, it returns the path component of its URI, which has the form * scheme://authority/path. * * @param path an HDFS {@link Path} * @return the path component of the {@link Path} URI */ public static String getPathWithoutScheme(Path path) { return path.toUri().getPath(); }
protected static File asFile(String path) { try { URI uri = new URI(path); if (uri.getScheme().equals("file")) { return new File(uri.getPath()); } else { throw new IllegalArgumentException("This path does not denote a local file."); } } catch (URISyntaxException | NullPointerException e) { throw new IllegalArgumentException("This path does not describe a valid local file URI.", e); } }
/** * The document fragment, without a preceeding '#' * * @param fragment * @return this URIBuilder instance, for method chaining. * @throws URISyntaxException if the given value contains illegal characters. */ public URIBuilder setFragment(String fragment) throws URISyntaxException { this.base = new URI(base.getScheme(), base.getUserInfo(), base.getHost(), base.getPort(), base.getPath(), base.getQuery(), fragment); return this; }
/** * Uses the scheme and authority of the object's current location and the path constructed * using the object's new name to construct a path for the object's new location. */ private Path constructRenamedPath(Path defaultNewPath, Path currentPath) { URI currentUri = currentPath.toUri(); return new Path(currentUri.getScheme(), currentUri.getAuthority(), defaultNewPath.toUri().getPath()); }
/** * Compare of path component. Does not consider schema; i.e. if schemas * different but <code>path</code> starts with <code>rootPath</code>, * then the function returns true * @param rootPath value to check for * @param path subject to check * @return True if <code>path</code> starts with <code>rootPath</code> */ public static boolean isStartingWithPath(final Path rootPath, final String path) { String uriRootPath = rootPath.toUri().getPath(); String tailUriPath = (new Path(path)).toUri().getPath(); return tailUriPath.startsWith(uriRootPath); }
/** * Determine if a uri is in asterisk-form according to * <a href="https://tools.ietf.org/html/rfc7230#section-5.3">rfc7230, 5.3</a>. */ public static boolean isAsteriskForm(URI uri) { return "*".equals(uri.getPath()) && uri.getScheme() == null && uri.getSchemeSpecificPart() == null && uri.getHost() == null && uri.getAuthority() == null && uri.getQuery() == null && uri.getFragment() == null; }
/** * Returns the parent of a path, i.e., everything that precedes the last separator * or <code>null</code> if at root. * * @return the parent of a path or <code>null</code> if at root. */ public Path getParent() { final String path = uri.getPath(); final int lastSlash = path.lastIndexOf('/'); final int start = hasWindowsDrive(path, true) ? 3 : 0; if ((path.length() == start) || // empty path (lastSlash == start && path.length() == start + 1)) { // at root return null; } String parent; if (lastSlash == -1) { parent = CUR_DIR; } else { final int end = hasWindowsDrive(path, true) ? 3 : 0; parent = path.substring(0, lastSlash == end ? end + 1 : lastSlash); } return new Path(uri.getScheme(), uri.getAuthority(), parent); }
/** * Creates a <code>LocalFileStatus</code> object from a given {@link File} object. * * @param f * the {@link File} object this <code>LocalFileStatus</code> refers to * @param fs * the file system the corresponding file has been read from */ public LocalFileStatus(final File f, final FileSystem fs) { this.file = f; this.path = new Path(fs.getUri().getScheme() + ":" + f.toURI().getPath()); }
private static Path reservedRawPath(URI uri) { return new Path(uri.getScheme(), uri.getAuthority(), CopyUtils.RAW_RESERVED_VIRTUAL_PATH + uri.getPath()); }