Base64解码 @param s 编码好的base64 @return 结果
(String s)
| 486 | * @return 结果 |
| 487 | */ |
| 488 | public static String decode(String s) { |
| 489 | int index = 0; |
| 490 | StringBuilder strBuff = new StringBuilder(); |
| 491 | StringBuilder resultBuff = new StringBuilder(); |
| 492 | while (true) { |
| 493 | //补零 |
| 494 | if (index == s.length() || s.charAt(index) == '=') { |
| 495 | int zeroCount = 8 - strBuff.length(); |
| 496 | for (int i = 0; i < zeroCount; i++) { |
| 497 | strBuff.append('0'); |
| 498 | } |
| 499 | index = -1; |
| 500 | } |
| 501 | //更新缓冲区字符 |
| 502 | while (index != -1 && strBuff.length() < 8 && index < s.length()) { |
| 503 | int chatIndex = getCharIndexInBaseChars(s.charAt(index++)); |
| 504 | strBuff.append(get6BitStr(chatIndex)); |
| 505 | } |
| 506 | //从缓冲区取8个字符 |
| 507 | String temp2 = strBuff.substring(0, 8); |
| 508 | int temp10 = Integer.valueOf(temp2, 2); |
| 509 | resultBuff.append((char) temp10); |
| 510 | strBuff.delete(0, 8); |
| 511 | //判断是否结束 |
| 512 | if (index == -1) |
| 513 | break; |
| 514 | } |
| 515 | return resultBuff.toString().trim(); |
| 516 | } |
| 517 | |
| 518 | /** |
| 519 | * 得到某个字符,在编码表的位置 |
no test coverage detected