This commit is contained in:
mm 2019-04-25 09:28:16 +08:00
parent a72ad6b6a6
commit e020c2fb63
2 changed files with 58 additions and 1 deletions

1
.gitignore vendored
View File

@ -8,5 +8,4 @@ target/
.settings/
*.log
bin/
src/test/
src/main/java/test/

View File

@ -0,0 +1,58 @@
package com.educoder.bridge.common.utils;
import org.junit.Test;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
public class Base64UtilTest {
@Test
public void test() {
String testCases = "W3siaW5wdXQiOiJcdTVhZTZcdTVhMjVcbjM1MDBcblx1NTk3M1xuNDUuNVxuXHU2NzA4XHU3NDAzXHU1ZTdmXHU1YmQyXHU1YmFiXG5cdTU0MjYiLCJvdXRwdXQiOiJcdThiZjdcdTVmNTVcdTUxNjVcdTVhZTZcdTVhMjVcdTRlMmFcdTRlYmFcdTRmZTFcdTYwNmZcdWZmMWFcblx1OGJmN1x1OGY5M1x1NTE2NVx1NTlkM1x1NTQwZFx1ZmYxYVxuXHU4YmY3XHU4ZjkzXHU1MTY1XHU1ZTc0XHU5Zjg0XHVmZjFhXG5cdThiZjdcdThmOTNcdTUxNjVcdTYwMjdcdTUyMmJcdWZmMWFcblx1OGJmN1x1OGY5M1x1NTE2NVx1NGY1M1x1OTFjZFx1ZmYxYVxuXHU4YmY3XHU4ZjkzXHU1MTY1XHU1NzMwXHU1NzQwXHVmZjFhXG5cdThiZjdcdThmOTNcdTUxNjVcdTY2MmZcdTU0MjZcdTVkZjJcdTVhNWFcdWZmMWFcblx1NGZlMVx1NjA2Zlx1NTk4Mlx1NGUwYlx1ZmYxYVxuXHRcdTU5ZDNcdTU0MGRcdWZmMWFcdTVhZTZcdTVhMjVcblx0XHU1ZTc0XHU5Zjg0XHVmZjFhMzUwMFx1NWM4MVxuXHRcdTYwMjdcdTUyMmJcdWZmMWFcdTU5NzNcblx0XHU0ZjUzXHU5MWNkXHVmZjFhNDUuNWtnXG5cdFx1NTczMFx1NTc0MFx1ZmYxYVx1NjcwOFx1NzQwM1x1NWU3Zlx1NWJkMlx1NWJhYlxuXHRcdTVhNWFcdTU0MjZcdWZmMWFcdTU0MjZcbiJ9XQ==";
testCases = Base64Util.decode(testCases);
System.out.println(testCases);
StringBuilder ins = new StringBuilder();
JSONArray cases = JSONArray.parseArray(testCases);
for (int i = 0; i < cases.size(); i++) {
String input = cases.getJSONObject(i).getString("input");
System.out.println("input " + i);
System.out.println(input);
ins.append(Base64Util.encodeNoSafe("".equals(input) ? " " : input) + ",");// 不要加引号
}
ins = ins.length() == 0 ? ins : ins.deleteCharAt(ins.length() - 1);
System.out.println(ins.toString());
}
@Test
public void test2() {
String buildResult = "{\"compileResult\":\"Y29tcGlsZSBzdWNjZXNzZnVsbHk=\",\"out\":[\"6K+35b2V5YWl5aum5ail5Liq5Lq65L+h5oGv77yaCuivt+i+k+WFpeWnk+WQje+8mgror7fovpPl haXlubTpvoTvvJoK6K+36L6T5YWl5oCn5Yir77yaCuivt+i+k+WFpeS9k+mHje+8mgror7fovpPl haXlnLDlnYDvvJoK6K+36L6T5YWl5piv5ZCm5bey5ama77yaCuS/oeaBr+WmguS4i++8mgoJ5aeT 5ZCN77ya5aum5ailCgnlubTpvoTvvJozNTAw5bKBCgnmgKfliKvvvJrlpbMKCeS9k+mHje+8mjQ1 LjVrZwoJ5Zyw5Z2A77ya5pyI55CD5bm/5a+S5a6rCgnlqZrlkKbvvJrlkKYK\"]}";
JSONObject buildResultInJson = JSONObject.parseObject(buildResult);
// 解码再编码是因为shell脚本中的编码是非URL safe编码
JSONArray outs = buildResultInJson.getJSONArray("out");
String out = Base64Util.decode(outs.getString(0));
System.out.println(out);
}
@Test
public void test3() {
String str = "5aum5ailCjM1MDAK5aWzCjQ1LjUK5pyI55CD5bm/5a";
str = Base64Util.decode(str);
System.out.println(str);
System.out.println("**********************");
str = "5aum5ailCjM1MDAK5aWzCjQ1LjUK5pyI55CD5bm/5a+S5a6rCuWQpg==";
str = Base64Util.decode(str);
System.out.println(str);
}
@Test
public void test4() {
String str = "5YWx5pyJMee7hOa1i-ivlembhu-8jOWFtuS4reaciTHnu4TmtYvor5Xnu5PmnpzkuI3ljLnphY3jgILor6bmg4XlpoLkuIvvvJo";
str = Base64Util.decode(str);
System.out.println(str);
}
}