Java HTTP Port create(String scheme, String rawUserInfo, String host, int port, String rawPath, String rawQuery, String rawFragment)

Here you can find the source of create(String scheme, String rawUserInfo, String host, int port, String rawPath, String rawQuery, String rawFragment)

Description

Returns a hierarchical URI constructed from the given components.

License

CDDL license

Parameter

Parameter Description
scheme the scheme component of the URI or null if none.
rawUserInfo the raw user-information component of the URI or null if none.
host the host component of the URI or null if none.
port the port number of the URI or -1 if none.
rawPath the raw path component of the URI or null if none.
rawQuery the raw query component of the URI or null if none.
rawFragment the raw fragment component of the URI or null if none.

Exception

Parameter Description
URISyntaxException if the resulting URI would be malformed per RFC 2396.

Return

the URI constructed from the given components.

Declaration

public static URI create(String scheme, String rawUserInfo, String host, int port, String rawPath,
        String rawQuery, String rawFragment) throws URISyntaxException 

Method Source Code


//package com.java2s;
/*/*  w ww.j a  va 2  s. com*/
 * The contents of this file are subject to the terms of the Common Development and
 * Distribution License (the License). You may not use this file except in compliance with the
 * License.
 *
 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
 * specific language governing permission and limitations under the License.
 *
 * When distributing Covered Software, include this CDDL Header Notice in each file and include
 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
 * Header, with the fields enclosed by brackets [] replaced by your own identifying
 * information: "Portions Copyright [year] [name of copyright owner]".
 *
 * Copyright 2010?2011 ApexIdentity Inc.
 * Portions Copyright 2011-2014 ForgeRock AS.
 */

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

public class Main {
    /**
     * Returns a hierarchical URI constructed from the given components. Differs from the URI
     * constructor by accepting raw versions of userInfo, path, query and fragment components.
     *
     * @param scheme the scheme component of the URI or {@code null} if none.
     * @param rawUserInfo the raw user-information component of the URI or {@code null} if none.
     * @param host the host component of the URI or {@code null} if none.
     * @param port the port number of the URI or {@code -1} if none.
     * @param rawPath the raw path component of the URI or {@code null} if none.
     * @param rawQuery the raw query component of the URI or {@code null} if none.
     * @param rawFragment the raw fragment component of the URI or {@code null} if none.
     * @return the URI constructed from the given components.
     * @throws URISyntaxException if the resulting URI would be malformed per RFC 2396.
     */
    public static URI create(String scheme, String rawUserInfo, String host, int port, String rawPath,
            String rawQuery, String rawFragment) throws URISyntaxException {
        StringBuilder sb = new StringBuilder();
        if (scheme != null) {
            sb.append(scheme).append(':');
        }
        if (host != null) {
            sb.append("//");
        }
        if (rawUserInfo != null) {
            sb.append(rawUserInfo).append('@');
        }
        if (host != null) {
            sb.append(host);
            if (port != -1) {
                sb.append(':').append(Integer.toString(port));
            }
        }
        if (rawPath != null) {
            sb.append(rawPath);
        }
        if (rawQuery != null) {
            sb.append('?').append(rawQuery);
        }
        if (rawFragment != null) {
            sb.append("#").append(rawFragment);
        }
        return new URI(sb.toString());
    }
}

Related

  1. checkHostAvailability(String host, int port)
  2. checkHostPort(String connectionString)
  3. checkIfPortAvailable(int port)
  4. create(final int[] ports)
  5. createProxy(final Proxy.Type type, final String host, final int port)
  6. createServer(final String host, final int port)