mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
修复FileTypeUtil.getType空指针问题
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user