This commit is contained in:
Looly 2021-06-05 11:16:14 +08:00
parent e7fb9759f3
commit f441b319da
2 changed files with 16 additions and 6 deletions

View File

@ -132,7 +132,7 @@ public class Base64Encoder {
*
* @param arr 被编码的数组
* @param isMultiLine 在76个char之后是CRLF还是EOF
* @param isUrlSafe 是否使用URL安全字符一般为{@code false}
* @param isUrlSafe 是否使用URL安全字符在URL Safe模式下=为URL中的关键字符不需要补充空余的byte位要去掉一般为{@code false}
* @return 编码后的bytes
*/
public static byte[] encode(byte[] arr, boolean isMultiLine, boolean isUrlSafe) {

View File

@ -23,6 +23,16 @@ public class Base64Test {
Assert.assertEquals(a, decodeStr);
}
@Test
public void encodeAndDecodeWithoutPaddingTest() {
String a = "伦家是一个非常长的字符串66";
String encode = Base64.encodeWithoutPadding(StrUtil.utf8Bytes(a));
Assert.assertEquals("5Lym5a625piv5LiA5Liq6Z2e5bi46ZW/55qE5a2X56ym5LiyNjY", encode);
String decodeStr = Base64.decodeStr(encode);
Assert.assertEquals(a, decodeStr);
}
@Test
public void encodeAndDecodeTest2() {
String a = "a61a5db5a67c01445ca2-HZ20181120172058/pdf/中国电信影像云单体网关Docker版-V1.2.pdf";