修复FileTypeUtil.getType空指针问题

This commit is contained in:
Looly 2024-07-15 20:24:10 +08:00
parent 068ba234da
commit 7262c7695f
3 changed files with 8 additions and 3 deletions

View File

@ -2,7 +2,7 @@
# 🚀Changelog
-------------------------------------------------------------------------------------------------------------
# 5.8.30(2024-07-11)
# 5.8.30(2024-07-15)
### 🐣新特性
* 【core 】 Converter转换规则变更空对象、空值转为Bean时创建默认对象而非nullissue#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)

View File

@ -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)));

View File

@ -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);
}