Java URL Create concatenate(URL server, String address)

Here you can find the source of concatenate(URL server, String address)

Description

Builds a complete URI given a URL that specifies the server and a string that is the remainder of the query.

License

Open Source License

Parameter

Parameter Description
server host, port, and optionally part of the path. For example "http://www.example.com/" or "https://plos.org/api/".
address the remainder of the path and query string. For example "articles/foo.pone.1234567?comments=true"

Return

a URI to the complete path and query string

Declaration

public static URI concatenate(URL server, String address) 

Method Source Code


//package com.java2s;
/*/*from   ww  w .j  a  va2  s.c  om*/
 * Copyright (c) 2017 Public Library of Science
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

import com.google.common.base.Preconditions;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

public class Main {
    /**
     * Builds a complete URI given a URL that specifies the server and a string that is the remainder of the query.
     *
     * @param server  host, port, and optionally part of the path.  For example "http://www.example.com/" or
     *                "https://plos.org/api/".
     * @param address the remainder of the path and query string.  For example "articles/foo.pone.1234567?comments=true"
     * @return a URI to the complete path and query string
     */
    public static URI concatenate(URL server, String address) {
        try {
            return new URL(server, Preconditions.checkNotNull(address)).toURI();
        } catch (MalformedURLException | URISyntaxException e) {
            throw new IllegalArgumentException(e);
        }
    }
}

Related

  1. buildUrl(String urlPrefix, String urlSuffix)
  2. buildURL(URI base, Multimap params)
  3. buildUrlPath(String baseUrl, String childUrl)
  4. buildUrlsList(final String domain, final String... paths)
  5. buildURLString(Iterable elements, String joiner)
  6. concatenateURL(final URL url, final String query)
  7. concatenateURL(URL url, String query)
  8. concatUrl(final URL baseUrl, final String extraPath)
  9. concaturl(final URL p_base, final String p_string)