Java 8 URI - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 URI class.

This code example shows how to use the following methods:getHost, getPath, getPort, getUserInfo
		    new GenericObjectPoolConfig()); 
	} 
    } 
 
    public JedisPool(final URI uri) {
	String h = uri.getHost();
	int port = uri.getPort();
	String password = uri.getUserInfo().split(":", 2)[1];
	int database = Integer.parseInt(uri.getPath().split("/", 2)[1]);
	this.internalPool = new GenericObjectPool<Jedis>(new JedisFactory(h,
		port, Protocol.DEFAULT_TIMEOUT, password, database, null),
		new GenericObjectPoolConfig()); 
    } 
 
    public JedisPool(final GenericObjectPoolConfig poolConfig,
	    final String host, int port, int timeout, final String password) {
	this(poolConfig, host, port, timeout, password,
		Protocol.DEFAULT_DATABASE, null); 
    } 
 
9
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getScheme
   */ 
  public static URI stringAsURI(String s) throws IOException {
    URI u = null;
    // try to make a URI 
    try { 
      u = new URI(s);
    } catch (URISyntaxException e){
      LOG.error("Syntax error in URI " + s
          + ". Please check hdfs configuration.", e);
    } 
 
    // if URI is null or scheme is undefined, then assume it's file:// 
    if(u == null || u.getScheme() == null){
      LOG.warn("Path " + s + " should be specified as a URI "
          + "in configuration files. Please update hdfs configuration."); 
      u = fileAsURI(new File(s));
    } 
    return u;
  } 
 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
        final ProtocolChannelClient.Configuration configuration = new ProtocolChannelClient.Configuration();
 
        if(client.getProtocol() == null) {
            // WFLY-1462 for compatibility assume remoting if the standard native port is configured 
            String protocol = client.getPort() == 9999 ? "remote://" : "http-remoting://";
            configuration.setUri(new URI(protocol + formatPossibleIpv6Address(client.getHost()) +  ":" + client.getPort()));
        } else  { 
            configuration.setUri(new URI(client.getProtocol() + "://" + formatPossibleIpv6Address(client.getHost()) +  ":" + client.getPort()));
        } 
        configuration.setOptionMap(DEFAULT_OPTIONS);
        final long timeout = client.getConnectionTimeout();
        if(timeout > 0) {
            configuration.setConnectionTimeout(timeout);
        } 
        return configuration;
    } 
 
    private static String formatPossibleIpv6Address(String address) {
        if (address == null) {
            return address;
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getHost, getPort, getUserInfo
 
    public  Context getRemoteContext() throws Exception {
        final Properties env = new Properties();
        env.put(Context.INITIAL_CONTEXT_FACTORY, org.jboss.naming.remote.client.InitialContextFactory.class.getName());
        URI webUri = managementClient.getWebUri();
        URI namingUri = new URI("http-remoting", webUri.getUserInfo(), webUri.getHost(), webUri.getPort(), "", "" ,"");
        env.put(Context.PROVIDER_URL, namingUri.toString());
        env.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");
        env.put("jboss.naming.client.security.callback.handler.class", CallbackHandler.class.getName());
        return new InitialContext(env);
    } 
 
    @Test 
    public void testRemoteLookup() throws Exception { 
        Context context = null;
        try { 
            context = getRemoteContext();
            assertEquals("TestValue", context.lookup("test"));
        } finally { 
            if (context != null)
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getHost
    } 
    return out;
  } 
 
  public static URI unredirect(URI uri) throws IOException {
    if (!REDIRECTOR_DOMAINS.contains(uri.getHost())) {
      return uri;
    } 
    URL url = uri.toURL();
 
    URLConnection conn = url.openConnection();
    if (!(conn instanceof HttpURLConnection)) {
      throw new IOException();
    } 
    HttpURLConnection connection = (HttpURLConnection) conn;
    connection.setInstanceFollowRedirects(false);
    connection.setDoInput(false);
    connection.setRequestMethod("HEAD");
    connection.setRequestProperty("User-Agent", "ZXing (Android)");
    try { 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getHost, getPath, getPort, getQuery
		assertEquals("Invalid method", HttpMethod.POST, request.getMethod());
	} 
 
	@Test
	public void getURI() throws Exception {
		URI uri = new URI("http://example.com/path?query");
		mockRequest.setServerName(uri.getHost());
		mockRequest.setServerPort(uri.getPort());
		mockRequest.setRequestURI(uri.getPath());
		mockRequest.setQueryString(uri.getQuery());
		assertEquals("Invalid uri", uri, request.getURI());
	} 
 
	@Test
	public void getContentType() throws Exception {
		HttpHeaders headers = request.getHeaders();
		assertNotNull("No HttpHeaders returned", headers);
 
		MediaType expected = MediaType.parseMediaType(mockFile.getContentType());
		MediaType actual = headers.getContentType();
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
  @Override 
  public URI getTrackingUri(ApplicationId id) throws URISyntaxException { 
    String jobSuffix = id.toString().replaceFirst("^application_", "job_"); 
    String historyServerAddress = 
        MRWebAppUtil.getJHSWebappURLWithScheme(getConf()); 
    return new URI(historyServerAddress + "/jobhistory/job/"+ jobSuffix); 
  } 
} 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getHost, getPort
        if (host == null) {
            String referrer = request.getHeader("referer");
            if (referrer != null) {
                URI url;
                try { 
                    url = new URI(referrer);
                    int port = url.getPort();
                    host = url.getHost() + ((port > -1) ? ":" + url.getPort() : "");
                } catch (URISyntaxException e) {
                    throw new RuntimeException("referrer '" + referrer + "' can't be parsed as a URL");
                } 
            } else { 
                throw new RuntimeException("neither the 'host' nor 'referer' headers were present in the HTTP response, I can't determine what URL OpenRefine is listening to.");
            } 
        } 
        return "http://" + host + "/command/core/authorize/" + provider.getHost();
    } 
} 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getHost, getPort
    AndroidHttpClient client = null;
 
    try { 
      Log.w("MmsSender", "Sending MMS1 of length: " + (mms != null ? mms.length : "null"));
      client                 = constructHttpClient(context, parameters);
      URI targetUrl          = new URI(parameters.getMmsc());
      HttpHost target        = new HttpHost(targetUrl.getHost(), targetUrl.getPort(), HttpHost.DEFAULT_SCHEME_NAME);
      HttpPost request       = new HttpPost(parameters.getMmsc());
      ByteArrayEntity entity = new ByteArrayEntity(mms);
 
      entity.setContentType("application/vnd.wap.mms-message");
 
      request.setEntity(entity);
      request.setParams(client.getParams());
      request.addHeader("Accept", "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic");
//      request.addHeader("x-wap-profile", "http://www.htcmms.com.tw/Android/Common/nexusone/ua-profile.xml"); 
      request.addHeader("x-wap-profile", "http://www.google.com/oha/rdf/ua-profile-kila.xml");
      HttpResponse response = client.execute(target, request);
      StatusLine status     = response.getStatusLine();
 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getHost, getScheme, getUserInfo
  /** 
   * @throws IllegalArgumentException if credentials for S3 cannot be 
   * determined. 
   */ 
  public void initialize(URI uri, Configuration conf) {
    if (uri.getHost() == null) {
      throw new IllegalArgumentException("Invalid hostname in URI " + uri);
    } 
     
    String userInfo = uri.getUserInfo();
    if (userInfo != null) {
      int index = userInfo.indexOf(':');
      if (index != -1) {
        accessKey = userInfo.substring(0, index);
        secretAccessKey = userInfo.substring(index + 1);
      } else { 
        accessKey = userInfo;
      } 
    } 
     

8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Java 8 URI Questions & Answers:

See Code Examples for Java 8 URI Methods: