1
0
mirror of https://gitee.com/dromara/hutool.git synced 2025-04-05 17:37:59 +08:00

base64 NPE verification

Merge pull request  from 蒋小小/v5-dev
This commit is contained in:
Looly 2023-09-12 10:38:17 +00:00 committed by Gitee
commit 8ee13fb5bf
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -30,6 +30,9 @@ public class Base64 {
* @return 编码后的bytes
*/
public static byte[] encode(byte[] arr, boolean lineSep) {
if (arr == null) {
return null;
}
return lineSep ?
java.util.Base64.getMimeEncoder().encode(arr) :
java.util.Base64.getEncoder().encode(arr);
@ -137,6 +140,9 @@ public class Base64 {
* @return 被加密后的字符串
*/
public static String encode(byte[] source) {
if (source == null) {
return null;
}
return java.util.Base64.getEncoder().encodeToString(source);
}
@ -148,6 +154,9 @@ public class Base64 {
* @since 5.5.2
*/
public static String encodeWithoutPadding(byte[] source) {
if (source == null) {
return null;
}
return java.util.Base64.getEncoder().withoutPadding().encodeToString(source);
}
@ -159,6 +168,9 @@ public class Base64 {
* @since 3.0.6
*/
public static String encodeUrlSafe(byte[] source) {
if (source == null) {
return null;
}
return java.util.Base64.getUrlEncoder().withoutPadding().encodeToString(source);
}