Java Utililty Methods URL Encode

List of utility methods to do URL Encode

Description

The list of methods to do URL Encode are organized into topic(s).

Method

StringURLEncode(String in)
Encodes a string as follows: - The ASCII characters 'a' through 'z', 'A' through 'Z', '0' through '9', and ".", "-", "*", "_" remain the same.
char[] chars = in.toCharArray();
char c = ' ';
StringBuffer out = new StringBuffer();
for (int i = 0; i < chars.length; i++) {
    c = chars[i];
    if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')) {
        out.append(c);
    } else if (c == ' ') {
...
StringurlEncode(String origString)
url Encode
StringBuffer sb = new StringBuffer();
int len = origString.length();
for (int i = 0; i < len; i++) {
    char c = origString.charAt(i);
    if (c == ' ')
        sb.append("%20");
    else
        sb.append(c);
...
StringURLencode(String s)
URL-encodes the given string
if (s != null) {
    StringBuffer tmp = new StringBuffer();
    int i = 0;
    try {
        while (true) {
            int b = (int) s.charAt(i++);
            if ((b >= 0x30 && b <= 0x39) || (b >= 0x41 && b <= 0x5A) || (b >= 0x61 && b <= 0x7A)) {
                tmp.append((char) b);
...
StringurlEncode(String str)
url Encode
str = str.replace('+', '-').replace('/', '_');
return str.replace("=", "");
StringurlEncode(String str)
url Encode
StringBuffer buf = new StringBuffer();
char c;
for (int i = 0; i < str.length(); i++) {
    c = str.charAt(i);
    if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) {
        buf.append(c);
    } else {
        buf.append("%").append(Integer.toHexString((int) str.charAt(i)));
...
StringurlEncode(String str)
url Encode
if (str == null)
    return null;
StringBuffer tmp = new StringBuffer();
for (int i = 0; i < str.length(); ++i) {
    char a = str.charAt(i);
    if (((a < ':') && (a > '/')) || ((a < '[') && (a > '@')) || ((a < '{') && (a > '`')) || (a == '_'))
        tmp.append(a);
    else if (a < '\16')
...
StringurlEncode(String urlPlain)
url Encode
String output = null;
output = urlPlain.replace("?", "&#63;");
return output;
StringurlEncodeFilename(char[] input)
This method encodes the URL, removes the spaces and brackets from the URL and replaces the same with "%20" and "%5B" and "%5D" and "%7B" "%7D".
if (input == null) {
    return null;
StringBuffer retu = new StringBuffer(input.length);
for (int i = 0; i < input.length; i++) {
    if (input[i] == ' ') {
        retu.append("%20"); 
    } else if (input[i] == '[') {
...
StringURLEncodeFilePath(String s)
given a string representing a path to a file, returns the url string for it.
String s1 = s.replace("#", "%23");
s1 = s1.replace("?", "%3F");
return s1;
StringurlEncodeForSpaces(String href)
url Encode For Spaces
return urlEncodeForSpaces(href.toCharArray());