URL-encode a String.
557604
private static String encode(String value, BitSet unescapedChars) {
        // Code from org.apache.commons.codec.net.URLCodec.encodeUrl(BitSet, byte[])
        final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        for (final byte c : value.getBytes(CHARSET)) {
            int b = c;
            if (b < 0) {
                b = 256 + b;
            }
            if (unescapedChars.get(b)) {
                buffer.write(b);
            } else {
                buffer.write(ESCAPE_CHAR);
                final char hex1 = Character.toUpperCase(Character.forDigit((b >> 4) & 0xF, HEXADECIMAL_RADIX));
                final char hex2 = Character.toUpperCase(Character.forDigit(b & 0xF, HEXADECIMAL_RADIX));
                buffer.write(hex1);
                buffer.write(hex2);
            }
        }
        return new String(buffer.toByteArray(), CHARSET);
    }
1106190
public static String encode(String value) throws UnsupportedEncodingException {
        if (isNullOrEmpty(value)) return value;
        return URLEncoder.encode(value, URL_ENCODING);
    }
1159095
private String encodeUri( String uri ) {
    String newUri = "";
    StringTokenizer st = new StringTokenizer( uri, "/ ", true );
    while ( st.hasMoreTokens()) {
      String tok = st.nextToken();
      if ( tok.equals( "/" ))
        newUri += "/";
      else if ( tok.equals( " " ))
        newUri += "%20";
      else {
        try {
          newUri += URLEncoder.encode( tok, "UTF-8" );
        } catch( UnsupportedEncodingException e ) {
          throw  Log.errRTExcept(e);
        }
      }
    }
    return newUri;
  }
330180
public static String encode(String url, Charset charset) {
		if (StrUtil.isEmpty(url)) {
			return url;
		}
		if (null == charset) {
			charset = CharsetUtil.defaultCharset();
		}
		return URLEncoder.DEFAULT.encode(url, charset);
	}
453418
function encode(data, parse_url) {
    var str;
    var t = typeof data;

    if (t == 'string' || t == 'number') {
        str = '' + data;
        data = new Buffer(str);
    } else if (Buffer.isBuffer(data)) {
        str = data.toString();
    } else if (Array.isArray(data)) {
        data = new Buffer(data);
        str = data.toString();
    } else {
        throw new Error("Bad data");
    }

    if (/^[0-9]+$/.test(str)) {
        if (data.length > 7089) {
            throw new Error("Too much data");
        }
        return encode_numeric(str);
    }

    if (/^[0-9A-Z \$%\*\+\.\/\:\-]+$/.test(str)) {
        if (data.length > 4296) {
            throw new Error("Too much data");
        }
        return encode_alphanum(str);
    }

    if (parse_url && /^https?:/i.test(str)) {
        return encode_url(str);
    }

    if (data.length > 2953) {
        throw new Error("Too much data");
    }
    return encode_8bit(data);
}
1281091
def urlencoded(body, charset='ascii', **kwargs):
    """"""
    return parse_query_string(text(body, charset=charset), False)
709267
def encode(string):
		

		result=".".join([ str(ord(s)) for s in string ])
		return  "%s." % (len(string)) + result
1255940
public String encodeURL(HttpSession session, String url) {
        return encodeURL(session, null, url, null);
    }
1241591
def to_bytes(url):
    """"""
    # Most URL schemes require ASCII. If that changes, the conversion
    # can be relaxed.
    # XXX get rid of to_bytes()
    if isinstance(url, str):
        try:
            url = url.encode("ASCII").decode()
        except UnicodeError:
            raise UnicodeError("URL " + repr(url) +
                               " contains non-ASCII characters")
    return url
531169
private String encode(String str) {
        if (str == null) {
            return null;
        }
        try {
            return URLEncoder.encode(str, Charsets.UTF_8.name());
        } catch (UnsupportedEncodingException e) {
            // Should never happen
            throw Throwables.propagate(e);
        }
    }
1307446
public static String encode(String url, String charset) throws UtilException {
		if (StrUtil.isEmpty(url)) {
			return url;
		}
		return encode(url, StrUtil.isBlank(charset) ? CharsetUtil.defaultCharset() : CharsetUtil.charset(charset));
	}
413606
private String encodeHttpParameter(String str){
		
		//It translates the empty space
		String encoded = str.replaceAll(" ", "%20");
		//It translates the & symbol				
		encoded = encoded.replaceAll("&", "%26");
		
//		encoded = encoded.replaceAll("$", "%24");
//		encoded = encoded.replaceAll("`", "%60");
//		encoded = encoded.replaceAll(":", "%3A");
//		encoded = encoded.replaceAll("<", "%3C");
//		encoded = encoded.replaceAll(">", "%3E");
//		encoded = encoded.replaceAll("[", "%5B");
//		encoded = encoded.replaceAll("]", "%5D");
//		encoded = encoded.replaceAll("{", "%7B");
//		encoded = encoded.replaceAll("}", "%7D");
		
		return encoded;
	}
1298515
private static final String urlEncode(String s) {
        try {
            return URLEncoder.encode(s, "UTF-8");
        } catch (Exception e) {
            logger.warn("Failed to encode '" + s + "'", e);
            return s;
        }
    }
507844
private String encode(String value, boolean query) {
    if (this.encode.isEncodingRequired()) {
      return query ? UriUtils.queryEncode(value, this.charset)
          : UriUtils.pathEncode(value, this.charset);
    } else {
      return value;
    }
  }
133120
public static String encodeAll(String url, Charset charset) throws UtilException {
		try {
			return java.net.URLEncoder.encode(url, charset.toString());
		} catch (UnsupportedEncodingException e) {
			throw new UtilException(e);
		}
	}
1203156
public static String encode(String input)
    {
        try
        {
            return URLEncoder.encode(input, "UTF-8");
        }
        catch (UnsupportedEncodingException e)
        {
            // This never happens.
            return input;
        }
    }
1063659
public static String encode(String str)
	{
		try
		{
			return java.net.URLEncoder.encode(str, "UTF-8");
		}
		catch(java.io.UnsupportedEncodingException ue)
		{
			return str;
		}
	}