/** * Determine if a uri is in origin-form according to * <a href="https://tools.ietf.org/html/rfc7230#section-5.3">rfc7230, 5.3</a>. */ public static boolean isOriginForm(URI uri) { return uri.getScheme() == null && uri.getSchemeSpecificPart() == null && uri.getHost() == null && uri.getAuthority() == null; }
private static URI checkMetastoreUri(URI uri) { requireNonNull(uri, "metastoreUri is null"); String scheme = uri.getScheme(); checkArgument(!isNullOrEmpty(scheme), "metastoreUri scheme is missing: %s", uri); checkArgument(scheme.equals("thrift"), "metastoreUri scheme must be thrift: %s", uri); checkArgument(uri.getHost() != null, "metastoreUri host is missing: %s", uri); checkArgument(uri.getPort() != -1, "metastoreUri port is missing: %s", uri); return uri; } }
/** * 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; }
/** * Appends the given path to the given base URI. * * @param base the base URI * @param path the path to append * @return the URI resulting from appending the base and the path * @throws URISyntaxException if URI syntax error is encountered */ public static URI appendPath(URI base, String path) throws URISyntaxException { return new URI(base.getScheme(), base.getAuthority(), PathUtils.concatPath(base.getPath(), path), base.getQuery(), base.getFragment()); }
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); } }
private static Path reservedRawPath(URI uri) { return new Path(uri.getScheme(), uri.getAuthority(), CopyUtils.RAW_RESERVED_VIRTUAL_PATH + uri.getPath()); }
/** * Get the scheme and authority at which this server is listening. */ public URI getListeningURI() { try { return new URI(this.serverUri.getScheme(), this.serverUri.getUserInfo(), this.serverUri.getHost(), this.port, null, null, null); } catch (URISyntaxException use) { throw new RuntimeException("Invalid URI. This is an error in code.", use); } }
static String absoluteURI(String serverOrigin, HttpServerRequest req) throws URISyntaxException { String absoluteURI; URI uri = new URI(req.uri()); String scheme = uri.getScheme(); if (scheme != null && (scheme.equals("http") || scheme.equals("https"))) { absoluteURI = uri.toString(); } else { String host = req.host(); if (host != null) { absoluteURI = req.scheme() + "://" + host + uri; } else { // Fall back to the server origin absoluteURI = serverOrigin + uri; } } return absoluteURI; }
@Override protected URI getInitURI(URI fsUri, org.apache.hadoop.conf.Configuration hadoopConfig) { final String scheme = fsUri.getScheme(); final String authority = fsUri.getAuthority(); if (scheme == null && authority == null) { fsUri = org.apache.hadoop.fs.FileSystem.getDefaultUri(hadoopConfig); } else if (scheme != null && authority == null) { URI defaultUri = org.apache.hadoop.fs.FileSystem.getDefaultUri(hadoopConfig); if (scheme.equals(defaultUri.getScheme()) && defaultUri.getAuthority() != null) { fsUri = defaultUri; } } LOG.debug("Using scheme {} for s3a file system backing the S3 File System", fsUri); return fsUri; }
private String pathToObjectName(final Path path) { org.apache.hadoop.fs.Path hadoopPath = HadoopFileSystem.toHadoopPath(path); if (!hadoopPath.isAbsolute()) { hadoopPath = new org.apache.hadoop.fs.Path(fs.getWorkingDirectory(), hadoopPath); } return hadoopPath.toUri().getScheme() != null && hadoopPath.toUri().getPath().isEmpty() ? "" : hadoopPath.toUri().getPath().substring(1); }
@Test public void testCreateHadoopFsWithoutConfig() throws Exception { final URI uri = URI.create("hdfs://localhost:12345/"); HadoopFsFactory factory = new HadoopFsFactory(); FileSystem fs = factory.create(uri); assertEquals(uri.getScheme(), fs.getUri().getScheme()); assertEquals(uri.getAuthority(), fs.getUri().getAuthority()); assertEquals(uri.getPort(), fs.getUri().getPort()); }
/** * Makes sure, that URI points to directory by adding slash to it. * Useful in relativizing URIs. */ public static URI addSlash(URI u) throws HiveException { if (u.getPath().endsWith("/")) { return u; } try { return new URI(u.getScheme(), u.getAuthority(), u.getPath() + "/", u.getQuery(), u.getFragment()); } catch (URISyntaxException e) { throw new HiveException("Could not append slash to a URI", e); } }
/** * 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()); }
public Builder overrideAbsolutesFromRequest( URI requestUri ) { // Find all default entries with absolute URIs and replace the corresponding host name entries with the one from the request uri. List<URIEntry> defaultEntries = entries.stream().filter( e -> e.uri.isAbsolute() && e.precedence == LOWEST ).collect( Collectors.toList() ); for ( URIEntry entry : defaultEntries ) { add( entry.key, entry.uri.getScheme(), requestUri.getHost(), entry.uri.getPort(), LOW ); } return this; }
/** * 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; }
public String siteUrlFor(String url, boolean forceSsl) throws URISyntaxException { String scheme = new URI(url).getScheme(); ServerSiteUrlConfig siteUrl = forceSsl || (scheme != null && scheme.equals("https")) ? getSecureSiteUrl() : serverConfig().getSiteUrl(); return siteUrl.siteUrlFor(url, false); }