Java URL Decode decode(String str)

Here you can find the source of decode(String str)

Description

decode

License

Open Source License

Declaration

static public Properties decode(String str) 

Method Source Code


//package com.java2s;
/*/*from w ww  .  ja v  a2  s  . c o  m*/
 * Flash and Java activities in Moodle
 * http://sourceforge.net/projects/flashjavamoodle/
 * 
 * Copyright (C) 2011 Departament d'Ensenyament de la Generalitat de Catalunya
 * 
 * This program is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU General Public License as published by 
 * the Free Software Foundation.
 */

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

import java.util.Properties;
import java.util.StringTokenizer;

public class Main {
    static public Properties decode(String str) {
        try {
            StringTokenizer st = new StringTokenizer(str, "&");
            Properties prop = new Properties();
            while (st.hasMoreElements()) {
                String t = st.nextToken();
                int i = t.indexOf("=");
                if (i > 0) {
                    String key = t.substring(0, i);
                    String dkey = URLDecoder.decode(key, "utf-8");
                    String value = t.substring(i + 1);
                    String dvalue = URLDecoder.decode(value, "utf-8");
                    prop.put(dkey, dvalue);
                }
            }
            return prop;
        } catch (UnsupportedEncodingException f) {
            throw new Error(f);
        }
    }
}

Related

  1. decode(String s, boolean formDecode)
  2. decode(String s, String enc)
  3. decode(String source)
  4. decode(String source, String encoding)
  5. decode(String source, String encoding)
  6. decode(String str)
  7. decode(String value)
  8. decode(String value)
  9. decode(String value)