本文整理汇总了Java中java.net.URI.getHost方法的典型用法代码示例。如果您正苦于以下问题:Java URI.getHost方法的具体用法?Java URI.getHost怎么用?Java URI.getHost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.URI
的用法示例。
在下文中一共展示了URI.getHost方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import java.net.URI; //导入方法依赖的package包/类
@Override
public void initialize(URI uri, Configuration conf) throws IOException {
super.initialize(uri, conf);
setConf(conf);
String host = uri.getHost();
if (host == null) {
throw new IOException("Incomplete HDFS URI, no host: "+ uri);
}
homeDirPrefix = conf.get(
DFSConfigKeys.DFS_USER_HOME_DIR_PREFIX_KEY,
DFSConfigKeys.DFS_USER_HOME_DIR_PREFIX_DEFAULT);
this.dfs = new DFSClient(uri, conf, statistics);
this.uri = URI.create(uri.getScheme()+"://"+uri.getAuthority());
this.workingDir = getHomeDirectory();
}
示例2: normalizeHostAndPort
import java.net.URI; //导入方法依赖的package包/类
static String normalizeHostAndPort(String address) {
try {
if (address == null) {
return null;
}
URI uri = new URI("http://" + address.trim());
String host = uri.getHost();
if (host == null || host.equals("") || host.equals("localhost") ||
host.equals("127.0.0.1") || host.equals("[0:0:0:0:0:0:0:1]")) {
return null;
}
InetAddress inetAddress = InetAddress.getByName(host);
if (inetAddress.isAnyLocalAddress() || inetAddress.isLoopbackAddress() ||
inetAddress.isLinkLocalAddress()) {
return null;
}
int port = uri.getPort();
return port == -1 ? host : host + ':' + port;
} catch (URISyntaxException |UnknownHostException e) {
return null;
}
}
示例3: getBaseUrl
import java.net.URI; //导入方法依赖的package包/类
/**
* Get the base url from a valid url
* @param url to get the base url from
* @return the base url if available, empty otherwise
*/
public Optional<String> getBaseUrl(String url) {
Optional<String> result = Optional.empty();
try {
URI uri = new URI(url);
String scheme = uri.getScheme();
String host = uri.getHost();
if (StringUtils.isNotBlank(scheme) && StringUtils.isNotBlank(host)) {
result = Optional.of(scheme + "://" + host + "/");
} else {
logger.warn("Failed to get baseUrl from {} because scheme (\"{}\") or host (\"{}\") could not be read", url, scheme, host);
}
} catch (URISyntaxException e) {
logger.warn("Failed to get baseUrl from {} due to error: {}", url, e.getMessage());
}
return result;
}
示例4: initializeClientFromURI
import java.net.URI; //导入方法依赖的package包/类
private void initializeClientFromURI(URI uri) {
if (!JedisURIHelper.isValid(uri)) {
throw new InvalidURIException(String.format(
"Cannot open Redis connection due invalid URI. %s", uri.toString()));
}
client = new Client(uri.getHost(), uri.getPort());
String password = JedisURIHelper.getPassword(uri);
if (password != null) {
client.auth(password);
client.getStatusCodeReply();
}
int dbIndex = JedisURIHelper.getDBIndex(uri);
if (dbIndex > 0) {
client.select(dbIndex);
client.getStatusCodeReply();
client.setDb(dbIndex);
}
}
示例5: parseEntry
import java.net.URI; //导入方法依赖的package包/类
@VisibleForTesting
static InetSocketAddress parseEntry(String type, String fn, String line) {
try {
URI uri = new URI("dummy", line, null, null, null);
int port = uri.getPort() == -1 ? 0 : uri.getPort();
InetSocketAddress addr = new InetSocketAddress(uri.getHost(), port);
if (addr.isUnresolved()) {
LOG.warn(String.format("Failed to resolve address `%s` in `%s`. " +
"Ignoring in the %s list.", line, fn, type));
return null;
}
return addr;
} catch (URISyntaxException e) {
LOG.warn(String.format("Failed to parse `%s` in `%s`. " + "Ignoring in " +
"the %s list.", line, fn, type));
}
return null;
}
示例6: getAddress
import java.net.URI; //导入方法依赖的package包/类
public InetSocketAddress getAddress(HttpClientImpl client) {
URI uri = uri();
if (uri == null) {
return authority();
}
int port = uri.getPort();
if (port == -1) {
if (uri.getScheme().equalsIgnoreCase("https")) {
port = 443;
} else {
port = 80;
}
}
String host = uri.getHost();
if (proxy(client) == null) {
return new InetSocketAddress(host, port);
} else {
return InetSocketAddress.createUnresolved(host, port);
}
}
示例7: getRecentHttpEndpoint
import java.net.URI; //导入方法依赖的package包/类
public String getRecentHttpEndpoint(String endpoint) {
URI uri = stringToUri(endpoint);
String scheme = uri.getScheme();
String host = uri.getHost();
if ("wss".equals(scheme)) {
scheme = "https";
} else {
scheme = "http";
}
return loggregatorRecentUriTemplate.expand(scheme, host).toString();
}
示例8: getAuthHeaderProvider
import java.net.URI; //导入方法依赖的package包/类
public static HawkAuthHeaderProvider getAuthHeaderProvider(final URI serverURI, final String tokenId, final byte[] reqHMACKey,
final boolean includePayloadVerificationHash) {
// We compute skew over time using SkewHandler. This yields an unchanging
// skew adjustment that the HawkAuthHeaderProvider uses to adjust its
// timestamps.
final String storageHostname = serverURI.getHost();
final SkewHandler storageServerSkewHandler = SkewHandler.getSkewHandlerForHostname(storageHostname);
final long storageServerSkew = storageServerSkewHandler.getSkewInSeconds();
return new HawkAuthHeaderProvider(tokenId, reqHMACKey, includePayloadVerificationHash, storageServerSkew);
}
示例9: getCanonicalHostPort
import java.net.URI; //导入方法依赖的package包/类
public static String getCanonicalHostPort(URI uri) {
int port = uri.getPort();
if (port == -1) {
String scheme = uri.getScheme();
if (scheme.equals("https") || scheme.equals("wss") || scheme.equals("wse+ssl")) {
port = 443;
}
else {
port = 80;
}
}
return uri.getHost()+":"+port;
}
示例10: isCDNURL
import java.net.URI; //导入方法依赖的package包/类
private static boolean isCDNURL(URI url) {
if (url != null) {
String uriHost = url.getHost();
if (uriHost.endsWith("fbcdn.net")) {
return true;
}
if (uriHost.startsWith("fbcdn") && uriHost.endsWith("akamaihd.net")) {
return true;
}
}
return false;
}
示例11: apply
import java.net.URI; //导入方法依赖的package包/类
/**
* Apply the filter to a given URI
*
* @param uri the URI to be filtered
* @return true if the host part of <code>uri</code> is equal to the inner host
*/
@Override
public boolean apply(final URI uri) {
if (uri.getHost() == null) throw new IllegalArgumentException("URI \"" + uri + "\" has no host");
// BURL hosts are always lower cased
return uri.getHost().equals(host);
}
示例12: getAddress
import java.net.URI; //导入方法依赖的package包/类
public static Optional<InetSocketAddress> getAddress(String address) {
// URI automatically validates schemes and returns ipv4 and ipv6 host and port in the right way
try {
String[] values = address.split("|");
URI uri = new URI("tcp://" + values[0]);
String host = uri.getHost();
int port = uri.getPort();
return Optional.of(new InetSocketAddress(host, port));
} catch (URISyntaxException e) {
log.debug("Failed to retrieve InetSocketAddress from String: {}", address);
}
return Optional.empty();
}
示例13: generateTmpDirectory
import java.net.URI; //导入方法依赖的package包/类
public static Path generateTmpDirectory(Configuration conf, String appId, Path outputPath) {
URI uri = outputPath.toUri();
String path = (uri.getScheme() != null ? uri.getScheme() : "hdfs") + "://"
+ (uri.getHost() != null ? uri.getHost() : "")
+ (uri.getPort() > 0 ? (":" + uri.getPort()) : "");
String user = conf.get(AngelConf.USER_NAME, "");
String tmpDir = conf.get(AngelConf.ANGEL_JOB_TMP_OUTPUT_PATH_PREFIX, "/tmp/" + user);
String finalTmpDirForApp = path + tmpDir + "/" + appId + "_" + UUID.randomUUID().toString();
LOG.info("tmp output dir is " + finalTmpDirForApp);
return new Path(finalTmpDirForApp);
}
示例14: appendQueryParameter
import java.net.URI; //导入方法依赖的package包/类
@Override
protected URI appendQueryParameter(URI uri, OAuth2AccessToken accessToken) {
try {
String query = uri.getRawQuery();
String queryFragment = this.resource.getTokenName() + "=" + URLEncoder.encode(accessToken.getValue(), "UTF-8");
if(query == null) {
query = queryFragment;
} else {
query = query + "&" + queryFragment;
}
String openid = (String) accessToken
.getAdditionalInformation().get("openid");
System.out.println("openid == " + openid);
String openIdQueryFragment = "openid=" + URLEncoder.encode(openid, "UTF-8");
query = query + "&" + openIdQueryFragment;
URI update = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), (String)null, (String)null);
StringBuffer sb = new StringBuffer(update.toString());
sb.append("?");
sb.append(query);
if(uri.getFragment() != null) {
sb.append("#");
sb.append(uri.getFragment());
}
System.out.println("appendQueryParameter == " + sb.toString());
return new URI(sb.toString());
} catch (URISyntaxException var7) {
throw new IllegalArgumentException("Could not parse URI", var7);
} catch (UnsupportedEncodingException var8) {
throw new IllegalArgumentException("Could not encode URI", var8);
}
}
示例15: apiBase
import java.net.URI; //导入方法依赖的package包/类
public static URI apiBase(final HttpServletRequest httpRequest) {
final URI current = currentUri(httpRequest);
try {
return new URI(current.getScheme(), null, current.getHost(), current.getPort(), basePath(current.getPath()),
null, null);
} catch (final URISyntaxException e) {
throw new IllegalArgumentException("Unable to generate base URI based on the current (`" + current + "`)",
e);
}
}