Util.java :  » API » taobaoonandroid » com » android » taobao » common » Android Open Source

Android Open Source » API » taobaoonandroid 
taobaoonandroid » com » android » taobao » common » Util.java
package com.android.taobao.common;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import android.util.Log;

public class Util {

  /**
   * URLHashMap
   * 
   * @param parameters
   * @return
   */
  public static Map<String, String> handleURLParameters(String result) {
    String[] parameters = result.split("&");
    Map<String, String> map = new HashMap<String, String>();
    for (int i = 0; i < parameters.length; i++) {
      int num = parameters[i].trim().indexOf("=");
      String key = parameters[i].trim().substring(0, num);
      String value = parameters[i].trim().substring(num + 1);
      map.put(key, value);
    }
    return map;
  }

  /**
   * BASE64
   * 
   * @param str
   * @return
   */
  public static String decodeBase64(String str) {
    String tag = "decodeBase64";
    String result = "";
    try {
      byte[] buf = new BASE64Decoder().decodeBuffer(str);
      result = new String(buf, "UTF-8");
    } catch (IOException e) {
      Log.i(tag, "Exception", e);
    }
    return result;
  }

  /**
   * BASE64
   * 
   * @param str
   * @return
   */
  public static String encodeBase64(String str) {
    String tag = "encodeBase64";
    String result = "";
    try {
      byte[] buf = str.getBytes("UTF-8");
      result = new BASE64Encoder().encode(buf);
    } catch (IOException e) {
      Log.i(tag, "Exception", e);
    }
    return result;
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.