Java URL Encode encode(Properties prop)

Here you can find the source of encode(Properties prop)

Description

encode

License

Open Source License

Declaration

static public String encode(Properties prop) 

Method Source Code


//package com.java2s;
/*//from  ww  w.j  a  va 2  s.com
 * 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.URLEncoder;
import java.util.Enumeration;
import java.util.Properties;

public class Main {
    static public String encode(Properties prop) {
        try {
            StringBuffer sb = new StringBuffer();
            Enumeration e = prop.keys();
            while (e.hasMoreElements()) {
                String key = (String) e.nextElement();
                String value = prop.getProperty(key);
                String ekey = URLEncoder.encode(key, "utf-8");
                String evalue = URLEncoder.encode(value, "utf-8");
                if (sb.length() > 0)
                    sb.append("&");
                sb.append(ekey);
                sb.append("=");
                sb.append(evalue);
            }
            return sb.toString();
        } catch (UnsupportedEncodingException f) {
            throw new Error(f);
        }
    }
}

Related

  1. encode(final String string)
  2. encode(final String value, final String charset)
  3. encode(HashMap map)
  4. encode(Object parameter)
  5. encode(Object value)
  6. encode(String _string, String _sEncoding)
  7. encode(String from, String to, String word)
  8. encode(String in)
  9. encode(String input)