com.qiniu.api.net.EncodeUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sdk Show documentation
Show all versions of sdk Show documentation
Qiniu Resource (Cloud) Storage SDK demo for Java
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);
}
}
}