mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
修复FileMagicNumber.getMagicNumber空指针问题
This commit is contained in:
parent
9a6ac21798
commit
68530d9e5b
@ -2,7 +2,7 @@
|
||||
# 🚀Changelog
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
# 5.8.28(2024-04-08)
|
||||
# 5.8.28(2024-04-11)
|
||||
|
||||
### 🐣新特性
|
||||
* 【core 】 修正XmlUtil的omitXmlDeclaration描述注释(issue#I9CPC7@Gitee)
|
||||
@ -11,6 +11,7 @@
|
||||
|
||||
### 🐞Bug修复
|
||||
* 【http 】 修复HttpUtil.urlWithFormUrlEncoded方法重复编码问题(issue#3536@Github)
|
||||
* 【core 】 修复FileMagicNumber.getMagicNumber空指针问题(issue#I9FE8B@Gitee)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
# 5.8.27(2024-03-29)
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cn.hutool.core.io;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Arrays;
|
||||
@ -1135,7 +1136,17 @@ public enum FileMagicNumber {
|
||||
this.extension = extension;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据给定的bytes,获取对应识别到的{@code FileMagicNumber}
|
||||
*
|
||||
* @param bytes bytes魔数
|
||||
* @return {@code FileMagicNumber}
|
||||
*/
|
||||
public static FileMagicNumber getMagicNumber(final byte[] bytes) {
|
||||
if(ObjUtil.isNull(bytes)){
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
final FileMagicNumber number = Arrays.stream(values())
|
||||
.filter(fileMagicNumber -> fileMagicNumber.match(bytes))
|
||||
.findFirst()
|
||||
|
Loading…
x
Reference in New Issue
Block a user