Java URI Create getUri(String s, String h, int p, String path)

Here you can find the source of getUri(String s, String h, int p, String path)

Description

Constructs the uri string and creates a URI object.

License

Open Source License

Parameter

Parameter Description
s scheme.
h host name.
p port number.
path of resource.

Return

URI object.

Declaration

public static URI getUri(String s, String h, int p, String path) throws URISyntaxException 

Method Source Code


//package com.java2s;

import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

public class Main {
    /**//from  w ww . jav  a 2  s.c o  m
     * Constructs the uri string and creates a URI object. Encodes the path
     * (calls the 7-parameter URI constructor).
     * 
     * @param s
     *            scheme.
     * @param h
     *            host name.
     * @param p
     *            port number.
     * @param path
     *            of resource.
     * @return URI object.
     */
    public static URI getUri(String s, String h, int p, String path) throws URISyntaxException {
        return getUri(s, null, h, p, path);
    }

    /**
     * Constructs the uri string and creates a URI object. Encodes the path
     * (calls the 7-parameter URI constructor).
     * 
     * @param s
     *            scheme.
     * @param u
     *            user info.
     * @param h
     *            host name.
     * @param p
     *            port number.
     * @param path
     *            of resource.
     * @return URI object.
     */
    public static URI getUri(String s, String u, String h, int p, String path) throws URISyntaxException {
        if (s == null)
            s = "file";
        if ("file".equals(s)) {
            h = null;
            p = -1;
        }
        if (path == null || path.equals(""))
            path = "/";
        return new URI(s, u, h, p, path, null, null);
    }

    /**
     * Constructs new uri from old, swapping out the old scheme for the new.
     * 
     * @param s
     *            scheme.
     * @param old
     *            URI object.
     * @return new URI object.
     */
    public static URI getUri(String s, URI old) throws URISyntaxException {
        String h = old.getHost();
        if (s == null || s.equals(""))
            s = "file";
        if (s.equals("file"))
            h = null;
        return new URI(s, old.getUserInfo(), h, old.getPort(), old.getPath(), old.getQuery(), old.getFragment());
    }

    /**
     * Constructs new uri from old, updating path.
     * 
     * @param uri
     *            from which to construct updated uri.
     * @param path
     *            new URI-consistent path.
     * @return new URI.
     */
    public static URI getUri(URI uri, String path) throws URISyntaxException {
        return getUri(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), path);
    }

    /**
     * Constructs the uri from the url using protocol, host, port and path.
     * 
     * @param url
     *            to convert.
     * @return uri from url
     */
    public static URI getUri(URL url) throws URISyntaxException {
        return getUri(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath());
    }
}

Related

  1. GetURI(String host, String port, String resource)
  2. getURI(String path)
  3. getURI(String path)
  4. getURI(String path, String name)
  5. getURI(String protocol, String authority, String path, Hashtable params)
  6. getURI(String spec)
  7. getUri(String uriName)
  8. getURIAddress(URI uri)
  9. getUriByEndpoint(String endpoint)