All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.qiniu.api.net.EncodeUtils Maven / Gradle / Ivy

There is a newer version: 6.1.9
Show newest version
package com.qiniu.api.net;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.commons.codec.binary.Base64;
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.message.BasicNameValuePair;

import com.qiniu.api.config.Config;

/**
 * URLEncoding is the alternate base64 encoding defined in RFC 4648. It is
 * typically used in URLs and file names.
 *
 */
public class EncodeUtils {

	public static byte[] urlsafeEncodeBytes(byte[] src) {
		return encodeBase64Ex(src);
	}

	public static byte[] urlsafeBase64Decode(String encoded){
		byte[] rawbs = toByte(encoded);
		for(int i=0;i) {
			@SuppressWarnings("unchecked")
			Map map = (HashMap) params;
			ArrayList list = new ArrayList();
			for (Entry entry : map.entrySet()) {
				list.add(new BasicNameValuePair(entry.getKey(), entry
						.getValue()));
			}
			return URLEncodedUtils.format(list, Config.CHARSET);
		}
		return null;
	}

	public static byte[] toByte(String s){
		try {
			return s.getBytes(Config.CHARSET);
		} catch (UnsupportedEncodingException e) {
			throw new RuntimeException(e);
		}
	}

	public static String toString(byte[] bs){
		try {
			return new String(bs, Config.CHARSET);
		} catch (UnsupportedEncodingException e) {
			throw new RuntimeException(e);
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy