Here you can find the source of normalizeUrl(String baseUrl, List
public static List<String> normalizeUrl(String baseUrl, List<String> urlList)
//package com.java2s; //License from project: Apache License import java.net.MalformedURLException; import java.net.URL; import java.util.*; public class Main { public static List<String> normalizeUrl(String baseUrl, List<String> urlList) { List<String> newUrlList = new ArrayList<>(); for (String url : urlList) { newUrlList.add(normalizeUrl(baseUrl, url)); }/*from w ww .j a va 2 s . c o m*/ return newUrlList; } public static List<String> normalizeUrl(String baseUrl, List<String> urlList, String urlSuffix) { List<String> newUrlList = new ArrayList<>(); for (String url : urlList) { newUrlList.add(normalizeUrl(baseUrl, url) + urlSuffix); } return newUrlList; } public static String normalizeUrl(String baseUrl, String urlString) { URL base; try { try { base = new URL(baseUrl); } catch (MalformedURLException e) { // the base is unsuitable, but the attribute may be abs on its // own, so try that URL abs = new URL(urlString); return abs.toExternalForm(); } // workaround: java resolves '//path/file + ?foo' to '//path/?foo', // not '//path/file?foo' as desired if (urlString.startsWith("?")) urlString = base.getPath() + urlString; URL abs = new URL(base, urlString); return abs.toExternalForm(); } catch (MalformedURLException e) { return ""; } } }