Java URL Create buildURLString(Iterable elements, String joiner)

Here you can find the source of buildURLString(Iterable elements, String joiner)

Description

build URL String

License

LGPL

Parameter

Parameter Description
elements a parameter
joiner a parameter

Declaration

@Deprecated
public static String buildURLString(Iterable<String> elements, String joiner) 

Method Source Code

//package com.java2s;
/*/* w  w w .j  ava2 s  .  com*/
 * Copyright (c) 2007-2012 The Broad Institute, Inc.
 * SOFTWARE COPYRIGHT NOTICE
 * This software and its documentation are the copyright of the Broad Institute, Inc. All rights are reserved.
 *
 * This software is supplied without any warranty or guaranteed support whatsoever. The Broad Institute is not responsible for its use, misuse, or functionality.
 *
 * This software is licensed under the terms of the GNU Lesser General Public License (LGPL),
 * Version 2.1 which is available at http://www.opensource.org/licenses/lgpl-2.1.php.
 */

import java.io.*;
import java.net.*;

import java.util.*;

public class Main {
    /**
     * @param elements
     * @param joiner
     * @return
     * @deprecated HttpUtils.openConnection does URL encoding itself
     * <p/>
     * Join the {@code elements} with the character {@code joiner},
     * URLencoding the {@code elements} along the way. {@code joiner}
     * is NOT URLEncoded
     * Example:
     * String[] parm_list = new String[]{"app les", "oranges", "bananas"};
     * String formatted = buildURLString(Arrays.asList(parm_list), "+");
     * <p/>
     * formatted will be "app%20les+oranges+bananas"
     */
    @Deprecated
    public static String buildURLString(Iterable<String> elements, String joiner) {

        Iterator<String> iter = elements.iterator();
        if (!iter.hasNext()) {
            return "";
        }
        String wholequery = iter.next();
        try {
            while (iter.hasNext()) {
                wholequery += joiner + URLEncoder.encode(iter.next(), "UTF-8");
            }
            return wholequery;
        } catch (UnsupportedEncodingException e) {
            throw new IllegalArgumentException("Bad argument in genelist: " + e.getMessage());
        }
    }
}

Related

  1. buildUrl(String URL, Map params)
  2. buildUrl(String urlPrefix, String urlSuffix)
  3. buildURL(URI base, Multimap params)
  4. buildUrlPath(String baseUrl, String childUrl)
  5. buildUrlsList(final String domain, final String... paths)
  6. concatenate(URL server, String address)
  7. concatenateURL(final URL url, final String query)
  8. concatenateURL(URL url, String query)
  9. concatUrl(final URL baseUrl, final String extraPath)