Example usage for java.net URI URI

List of usage examples for java.net URI URI

Introduction

In this page you can find the example usage for java.net URI URI.

Prototype

public URI(String scheme, String authority, String path, String query, String fragment)
        throws URISyntaxException 

Source Link

Document

Constructs a hierarchical URI from the given components.

Usage

From source file:Main.java

public static void main(String[] args) throws URISyntaxException {
    URI uri = new URI("http", "abc", "/def", "name=value", "xyz");
    System.out.println(uri);//w ww.jav a2  s.com
}

From source file:at.bitfire.davdroid.URIUtils.java

public static URI ensureTrailingSlash(URI href) {
    if (!href.getPath().endsWith("/")) {
        try {/*from w w  w  .j a v  a  2s  .c  o m*/
            URI newURI = new URI(href.getScheme(), href.getAuthority(), href.getPath() + "/", null, null);
            Log.d(TAG, "Appended trailing slash to collection " + href + " -> " + newURI);
            href = newURI;
        } catch (URISyntaxException e) {
        }
    }
    return href;
}

From source file:Main.java

/**
 * Encode a URL path and optional query string according to RFC 2396.
 *
 * @param path Path to resource/*  www .jav  a 2s. c o  m*/
 * @param query Query string
 * @return
 */
public static String escapeUrlPath(String path, String query) {
    try {
        URI uri;
        uri = new URI("http", "authority", path, query, null);
        return uri.getRawPath() + "?" + uri.getRawQuery();
    } catch (URISyntaxException e) {
        /* This should not happen */
        return null;
    }
}

From source file:org.eclipse.aether.transport.http.UriUtils.java

public static URI resolve(URI base, URI ref) {
    String path = ref.getRawPath();
    if (path != null && path.length() > 0) {
        path = base.getRawPath();/*from  w  w w. j  a v  a  2  s  .  co  m*/
        if (path == null || !path.endsWith("/")) {
            try {
                base = new URI(base.getScheme(), base.getAuthority(), base.getPath() + '/', null, null);
            } catch (URISyntaxException e) {
                throw new IllegalStateException(e);
            }
        }
    }
    return URIUtils.resolve(base, ref);
}

From source file:Main.java

/**
 * Removes dot segments according to RFC 3986, section 5.2.4
 *
 * @param uri the original URI// w  w w. j  av  a 2 s . c  o  m
 * @return the URI without dot segments
 */
private static URI removeDotSegments(URI uri) {
    String path = uri.getPath();
    if ((path == null) || (path.indexOf("/.") == -1)) {
        // No dot segments to remove
        return uri;
    }
    String[] inputSegments = path.split("/");
    Stack<String> outputSegments = new Stack<String>();
    for (int i = 0; i < inputSegments.length; i++) {
        if ((inputSegments[i].length() == 0) || (".".equals(inputSegments[i]))) {
            // Do nothing
        } else if ("..".equals(inputSegments[i])) {
            if (!outputSegments.isEmpty()) {
                outputSegments.pop();
            }
        } else {
            outputSegments.push(inputSegments[i]);
        }
    }
    StringBuilder outputBuffer = new StringBuilder();
    for (String outputSegment : outputSegments) {
        outputBuffer.append('/').append(outputSegment);
    }
    try {
        return new URI(uri.getScheme(), uri.getAuthority(), outputBuffer.toString(), uri.getQuery(),
                uri.getFragment());
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e);
    }
}

From source file:br.com.autonomiccs.autonomic.plugin.common.utils.NotifySmartAcsStartUpUtils.java

public void sendModuleStartUp(Class<?> clazz) {
    try {/*w w  w.ja  v  a  2  s . c  o  m*/
        URI uri = new URI("http", "smartcloudstack.lrg.ufsc.br:8080", "/boot/log/" + uuid,
                String.format("msg=Module initialized[%s]", ObjectUtils.toString(clazz)), null);
        httpUtils.executeHttpGetRequest(uri.toURL());
    } catch (IOException | URISyntaxException e) {
        logger.info("Problems while notifying home about the modules startup.");
    }
}

From source file:com.mashape.unirest.request.HttpRequest.java

private URL parseUrl(String s) throws Exception {
    URL u = new URL(s);
    return new URI(u.getProtocol(), u.getAuthority(), u.getPath(), u.getQuery(), u.getRef()).toURL();
}

From source file:com.subgraph.vega.impl.scanner.requests.AbstractRequestBuilder.java

protected URI createUri(String path, String query) {
    final String q = (query == null) ? (baseURI.getQuery()) : (query);
    try {/*from  w  w  w  .  j a va2 s  .  c  om*/
        return new URI(baseURI.getScheme(), baseURI.getAuthority(), path, q, null);
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(
                "Failed to create new URI with path = " + path + " and query = " + q);
    }
}