Here you can find the source of getUri(String s, String h, int p, String path)
Parameter | Description |
---|---|
s | scheme. |
h | host name. |
p | port number. |
path | of resource. |
public static URI getUri(String s, String h, int p, String path) throws URISyntaxException
//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()); } }