当前位置: 首页>>代码示例>>Java>>正文


Java URI.getHost方法代码示例

本文整理汇总了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();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:18,代码来源:DistributedFileSystem.java

示例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;
    }
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:23,代码来源:Peers.java

示例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;
}
 
开发者ID:xabgesagtx,项目名称:mensa-api,代码行数:22,代码来源:WebUtils.java

示例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);
  }
}
 
开发者ID:x7-framework,项目名称:x7,代码行数:22,代码来源:BinaryJedis.java

示例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;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:19,代码来源:HostFileManager.java

示例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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:HttpRequestImpl.java

示例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();
}
 
开发者ID:SAP,项目名称:cf-java-client-sap,代码行数:15,代码来源:LoggregatorClient.java

示例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);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:12,代码来源:FirefoxDataRequestUtils.java

示例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;
}
 
开发者ID:Datatellit,项目名称:xlight_android_native,代码行数:14,代码来源:WebSocketNativeDelegateHandler.java

示例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;
}
 
开发者ID:MobileDev418,项目名称:AndroidBackendlessChat,代码行数:16,代码来源:ImageResponseCache.java

示例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);
}
 
开发者ID:LAW-Unimi,项目名称:BUbiNG,代码行数:13,代码来源:HostEquals.java

示例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();
}
 
开发者ID:AidosKuneen,项目名称:aidos-node,代码行数:14,代码来源:PD.java

示例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);
}
 
开发者ID:Tencent,项目名称:angel,代码行数:12,代码来源:HdfsUtil.java

示例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);
    }
}
 
开发者ID:luotuo,项目名称:springboot-security-wechat,代码行数:32,代码来源:MyOAuth2RestTemplate.java

示例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);
    }
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:12,代码来源:Urls.java


注:本文中的java.net.URI.getHost方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。