mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
修复FileTypeUtil.getType空指针问题
This commit is contained in:
parent
068ba234da
commit
7262c7695f
@ -2,7 +2,7 @@
|
||||
# 🚀Changelog
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
# 5.8.30(2024-07-11)
|
||||
# 5.8.30(2024-07-15)
|
||||
|
||||
### 🐣新特性
|
||||
* 【core 】 Converter转换规则变更,空对象、空值转为Bean时,创建默认对象,而非null(issue#3649@Github)
|
||||
@ -12,6 +12,7 @@
|
||||
* 【core 】 修复FileUtil.cleanEmpty无法正确清空递归空目录问题(pr#1233@Gitee)
|
||||
* 【core 】 修复BeanUtil.copyProperties中mapToMap时key被转为String问题(issue#3645@Github)
|
||||
* 【core 】 修复FileUtil.file末尾换行符导致路径判断错误的问题(issue#IAB65V@Gitee)
|
||||
* 【core 】 修复FileTypeUtil.getType空指针问题(issue#IAD5JM@Gitee)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
# 5.8.29(2024-07-03)
|
||||
|
@ -53,6 +53,9 @@ public class FileTypeUtil {
|
||||
* @return 文件类型,未找到为{@code null}
|
||||
*/
|
||||
public static String getType(String fileStreamHexHead) {
|
||||
if(StrUtil.isBlank(fileStreamHexHead)){
|
||||
return null;
|
||||
}
|
||||
if (MapUtil.isNotEmpty(FILE_TYPE_MAP)) {
|
||||
for (final Entry<String, String> fileTypeEntry : FILE_TYPE_MAP.entrySet()) {
|
||||
if (StrUtil.startWithIgnoreCase(fileStreamHexHead, fileTypeEntry.getKey())) {
|
||||
@ -60,7 +63,7 @@ public class FileTypeUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
byte[] bytes = (HexUtil.decodeHex(fileStreamHexHead));
|
||||
byte[] bytes = HexUtil.decodeHex(fileStreamHexHead);
|
||||
return FileMagicNumber.getMagicNumber(bytes).getExtension();
|
||||
}
|
||||
|
||||
@ -70,6 +73,7 @@ public class FileTypeUtil {
|
||||
* @param in 文件流
|
||||
* @param fileHeadSize 自定义读取文件头部的大小
|
||||
* @return 文件类型,未找到为{@code null}
|
||||
* @throws IORuntimeException IO异常
|
||||
*/
|
||||
public static String getType(InputStream in, int fileHeadSize) throws IORuntimeException {
|
||||
return getType((IoUtil.readHex(in, fileHeadSize, false)));
|
||||
|
@ -529,7 +529,7 @@ public class IoUtil extends NioUtil {
|
||||
public static String readHex8192Upper(InputStream in) throws IORuntimeException {
|
||||
try {
|
||||
int i = in.available();
|
||||
return readHex(in, Math.min(8192, in.available()), false);
|
||||
return readHex(in, Math.min(8192, i), false);
|
||||
} catch (IOException e) {
|
||||
throw new IORuntimeException(e);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user