Skip to content

remove useless base64 code #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 17, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 6 additions & 22 deletions src/main/java/com/qiniu/api/net/EncodeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,14 @@
/**
* 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) {
if (src.length % 3 == 0) {
return encodeBase64Ex(src);
}

byte[] b = encodeBase64Ex(src);
if (b.length % 4 == 0) {
return b;
}

int pad = 4 - b.length % 4;
byte[] b2 = new byte[b.length + pad];
System.arraycopy(b, 0, b2, 0, b.length);
b2[b.length] = '=';
if (pad > 1) {
b2[b.length + 1] = '=';
}
return b2;
return encodeBase64Ex(src);
}

public static byte[] urlsafeBase64Decode(String encoded){
byte[] rawbs = toByte(encoded);
for(int i=0;i<rawbs.length;i++){
Expand All @@ -51,7 +35,7 @@ public static byte[] urlsafeBase64Decode(String encoded){
}
return Base64.decodeBase64(rawbs);
}

public static String urlsafeEncodeString(byte[] src) {
return toString(urlsafeEncodeBytes(src));
}
Expand Down Expand Up @@ -91,15 +75,15 @@ public static String encodeParams(Object params) {
}
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);
Expand Down