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

StringencodeUrl(String url, String encoding)
Returns the ASCII-escaped representation (encoded in the specified encoding) of the given URL (encoded in UTF-16).
if (url == null) {
    return url;
int len = url.length();
if (len == 0) {
    return url;
StringBuffer result = new StringBuffer();
...
StringencodeURLComponent(final String s)
encode URL Component
if (s == null) {
    return "";
final StringBuilder sb = new StringBuilder();
try {
    for (int i = 0; i < s.length(); i++) {
        final char c = s.charAt(i);
        if (((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z')) || ((c >= '0') && (c <= '9'))
...
StringencodeUrlPath(String pathSegment)
encode Url Path
final StringBuilder sb = new StringBuilder();
try {
    for (int i = 0; i < pathSegment.length(); i++) {
        final char c = pathSegment.charAt(i);
        if (((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z')) || ((c >= '0') && (c <= '9'))
                || (c == '-') || (c == '.') || (c == '_') || (c == '~')) {
            sb.append(c);
        } else {
...
StringunpaddedBase64UrlEncoded(final String unencodedString)
unpadded Base Url Encoded
return unpaddedBase64UrlEncoded(unencodedString.getBytes());
StringuriDecode(String src)
uri Decode
boolean query = false;
boolean decoded = false;
int length = src.length();
ByteArrayOutputStream bos = new ByteArrayOutputStream(length);
for (int i = 0; i < length; i++) {
    byte ch = (byte) src.charAt(i);
    if (ch == '?') {
        query = true;
...
StringuriDecode(String uri)
Convert a URI reference (URI or URI fragment), in US-ASCII, with escaped characters taken from UTF-8, to the corresponding Unicode string.
try {
    byte ascii[] = uri.getBytes("US-ASCII");
    byte utf8[] = new byte[ascii.length];
    int in = 0;
    int out = 0;
    while (in < ascii.length) {
        if (ascii[in] == (byte) '%') {
            in++;
...
StringuriEncode(String uriRef)
Convert a Unicode string (which is assumed to represent a URI or URI fragment) to an RFC 2396-compliant URI reference by first converting it to bytes in UTF-8 and then encoding the resulting bytes as specified by the RFC.
try {
    byte utf8[] = uriRef.getBytes("UTF-8");
    byte rsltAscii[] = new byte[utf8.length * 6];
    int in = 0;
    int out = 0;
    while (in < utf8.length) {
        switch (utf8[in]) {
        case (byte) 'a':
...
StringURLEncode(byte[] input)
URL Encode
StringBuffer ret;
int i, temp;
if (input == null)
    return null;
ret = new StringBuffer();
for (i = 0; i < input.length; i++) {
    temp = input[i] & 0xff; 
    if ((temp >= 0x30 && temp <= 0x39) || 
...
StringurlEncode(byte[] rs)
url Encode
StringBuffer sb = new StringBuffer(rs.length * 2);
for (int i = 0; i < rs.length; i++) {
    char c = (char) rs[i];
    switch (c) {
    case '_':
    case '.':
    case '*':
    case '-':
...
Stringurlencode(byte[] unencodedBytes)
Encodes an array of plain bytes into a urlencoded string
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < unencodedBytes.length; i++) {
    if (((unencodedBytes[i] >= 'a') && (unencodedBytes[i] <= 'z'))
            || ((unencodedBytes[i] >= 'A') && (unencodedBytes[i] <= 'Z'))
            || ((unencodedBytes[i] >= '0') && (unencodedBytes[i] <= '9')) || (unencodedBytes[i] == '.')
            || (unencodedBytes[i] == '-') || (unencodedBytes[i] == '*') || (unencodedBytes[i] == '_')) {
        buffer.append((char) unencodedBytes[i]);
    } else if (unencodedBytes[i] == ' ') {
...