mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-24 18:04:54 +08:00
rename
This commit is contained in:
parent
edbd5140aa
commit
b216e554c0
@ -44,8 +44,8 @@ public class Base64 {
|
||||
*/
|
||||
public static byte[] encode(final byte[] arr, final boolean lineSep) {
|
||||
return lineSep ?
|
||||
java.util.Base64.getMimeEncoder().encode(arr) :
|
||||
java.util.Base64.getEncoder().encode(arr);
|
||||
java.util.Base64.getMimeEncoder().encode(arr) :
|
||||
java.util.Base64.getEncoder().encode(arr);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -253,7 +253,7 @@ public class Base64 {
|
||||
* @return 是否为Base64
|
||||
* @since 5.7.5
|
||||
*/
|
||||
public static boolean isBase64(final CharSequence base64) {
|
||||
public static boolean isTypeBase64(final CharSequence base64) {
|
||||
if (base64 == null || base64.length() < 2) {
|
||||
return false;
|
||||
}
|
||||
@ -265,17 +265,17 @@ public class Base64 {
|
||||
return false;
|
||||
}
|
||||
|
||||
return isBase64(bytes);
|
||||
return isTypeBase64(bytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否为Base64
|
||||
* 检查是否为Base64格式
|
||||
*
|
||||
* @param base64Bytes Base64的bytes
|
||||
* @return 是否为Base64
|
||||
* @since 5.7.5
|
||||
*/
|
||||
public static boolean isBase64(final byte[] base64Bytes) {
|
||||
public static boolean isTypeBase64(final byte[] base64Bytes) {
|
||||
if (base64Bytes == null || base64Bytes.length < 3) {
|
||||
return false;
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ public class ArrayConverter extends AbstractConverter {
|
||||
// 字符串转bytes,首先判断是否为Base64,是则转换,否则按照默认getBytes方法。
|
||||
if(targetComponentType == byte.class){
|
||||
final String str = value.toString();
|
||||
if(Base64.isBase64(str)){
|
||||
if(Base64.isTypeBase64(str)){
|
||||
return Base64.decode(value.toString());
|
||||
}
|
||||
return str.getBytes();
|
||||
|
@ -16,20 +16,20 @@ import org.junit.jupiter.api.Test;
|
||||
public class Base64Test {
|
||||
|
||||
@Test
|
||||
public void isBase64Test(){
|
||||
Assertions.assertTrue(Base64.isBase64(Base64.encode(RandomUtil.randomString(1000))));
|
||||
public void isTypeBase64Test(){
|
||||
Assertions.assertTrue(Base64.isTypeBase64(Base64.encode(RandomUtil.randomString(1000))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isBase64Test2(){
|
||||
public void isTypeBase64Test2(){
|
||||
String base64 = "dW1kb3MzejR3bmljM2J6djAyZzcwbWk5M213Nnk3cWQ3eDJwOHFuNXJsYmMwaXhxbmg0dmxrcmN0anRkbmd3\n" +
|
||||
"ZzcyZWFwanI2NWNneTg2dnp6cmJoMHQ4MHpxY2R6c3pjazZtaQ==";
|
||||
Assertions.assertTrue(Base64.isBase64(base64));
|
||||
Assertions.assertTrue(Base64.isTypeBase64(base64));
|
||||
|
||||
// '=' 不位于末尾
|
||||
base64 = "dW1kb3MzejR3bmljM2J6=djAyZzcwbWk5M213Nnk3cWQ3eDJwOHFuNXJsYmMwaXhxbmg0dmxrcmN0anRkbmd3\n" +
|
||||
"ZzcyZWFwanI2NWNneTg2dnp6cmJoMHQ4MHpxY2R6c3pjazZtaQ=";
|
||||
Assertions.assertFalse(Base64.isBase64(base64));
|
||||
Assertions.assertFalse(Base64.isTypeBase64(base64));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user