Here you can find the source of concatenateURL(final URL url, final String query)
Parameter | Description |
---|---|
url | URL to base off |
query | Query to append to URL |
public static URL concatenateURL(final URL url, final String query)
//package com.java2s; //License from project: Open Source License import java.net.MalformedURLException; import java.net.URL; public class Main { /**//from w w w.j av a 2s . c o m * Concatenates the given {@link java.net.URL} and query. * * @param url URL to base off * @param query Query to append to URL * @return URL constructed */ public static URL concatenateURL(final URL url, final String query) { try { if (url.getQuery() != null && url.getQuery().length() > 0) { return new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getFile() + "&" + query); } else { return new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getFile() + "?" + query); } } catch (final MalformedURLException ex) { throw new IllegalArgumentException("Could not concatenate given URL with GET arguments!", ex); } } }