FileDocCategorySizeDatePackage
URLDecoder.javaAPI DocExample919Thu Apr 03 15:15:58 BST 1997None

URLDecoder

public class URLDecoder extends Object
Turns Strings of x-www-form-urlEncoded format into regular text.
version
1.0, 4/3/1996
author
Elliotte Rusty Harold

Fields Summary
Constructors Summary
private URLDecoder()

 
Methods Summary
public static java.lang.Stringdecode(java.lang.String s)
Translates String from x-www-form-urlEncoded format into text.

param
s String to be translated
return
the translated String.

  
    ByteArrayOutputStream out = new ByteArrayOutputStream(s.length());
  
    for (int i = 0; i < s.length(); i++) {
      int c = (int) s.charAt(i);
      if (c == '+") {
        out.write(' ");
      }
      else if (c == '%") {
        int c1 = Character.digit(s.charAt(++i), 16);
        int c2 = Character.digit(s.charAt(++i), 16);
        out.write((char) (c1 * 16 + c2));
      }
      else {
        out.write(c);
      }
    } // end for

    return out.toString();