Java URL Create concaturl(final URL p_base, final String p_string)

Here you can find the source of concaturl(final URL p_base, final String p_string)

Description

concats an URL with a path

License

LGPL

Parameter

Parameter Description
p_base base URL
p_string additional path

Exception

Parameter Description
URISyntaxException thrown on syntax error
MalformedURLException thrown on malformat

Return

new URL

Declaration

public static URL concaturl(final URL p_base, final String p_string)
        throws MalformedURLException, URISyntaxException 

Method Source Code

//package com.java2s;
/*//  w  w w.ja v  a  2 s. co  m
 * @cond LICENSE
 * ######################################################################################
 * # LGPL License                                                                       #
 * #                                                                                    #
 * # This file is part of the Asimov - Agentbased Passenger Train Delay                 #
 * # This program is free software: you can redistribute it and/or modify               #
 * # it under the terms of the GNU Lesser General Public License as                     #
 * # published by the Free Software Foundation, either version 3 of the                 #
 * # License, or (at your option) any later version.                                    #
 * #                                                                                    #
 * # This program is distributed in the hope that it will be useful,                    #
 * # but WITHOUT ANY WARRANTY; without even the implied warranty of                     #
 * # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                      #
 * # GNU Lesser General Public License for more details.                                #
 * #                                                                                    #
 * # You should have received a copy of the GNU Lesser General Public License           #
 * # along with this program. If not, see http://www.gnu.org/licenses/                  #
 * ######################################################################################
 * @endcond
 */

import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;

public class Main {
    /**
     * concats an URL with a path
     *
     * @param p_base base URL
     * @param p_string additional path
     * @return new URL
     *
     * @throws URISyntaxException thrown on syntax error
     * @throws MalformedURLException thrown on malformat
     */
    public static URL concaturl(final URL p_base, final String p_string)
            throws MalformedURLException, URISyntaxException {
        return new URL(p_base.toString() + p_string).toURI().normalize()
                .toURL();
    }
}

Related

  1. buildURLString(Iterable elements, String joiner)
  2. concatenate(URL server, String address)
  3. concatenateURL(final URL url, final String query)
  4. concatenateURL(URL url, String query)
  5. concatUrl(final URL baseUrl, final String extraPath)
  6. constructURL(URL base, String url, boolean stripRef)
  7. constructURLQueryString(Map urlParameters)
  8. constructURLString(Map parameters)
  9. convertToURL(String host)