mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
FileTypeUtil增加null判断
This commit is contained in:
parent
1e06dd4674
commit
4ab74605be
@ -2,7 +2,7 @@
|
||||
# 🚀Changelog
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
# 5.8.24(2023-12-09)
|
||||
# 5.8.24(2023-12-11)
|
||||
|
||||
### 🐣新特性
|
||||
* 【cache 】 Cache增加get重载,可自定义超时时间(issue#I8G0DL@Gitee)
|
||||
@ -10,6 +10,7 @@
|
||||
* 【db 】 增加识别OpenGauss的驱动类(issue#I8K6C0@Gitee)
|
||||
* 【core 】 修复CharSequenceUtil注释和引用,避免循环引用
|
||||
* 【extra 】 SpringUtil增加getProperty重载(pr#1122@Gitee)
|
||||
* 【core 】 FileTypeUtil增加null判断(issue#3419@Github)
|
||||
|
||||
### 🐞Bug修复
|
||||
* 【core 】 修复LocalDateTime#parseDate未判断空问题问题(issue#I8FN7F@Gitee)
|
||||
|
@ -79,12 +79,16 @@ public class FileTypeUtil {
|
||||
* 根据文件流的头部信息获得文件类型<br>
|
||||
* 注意此方法会读取头部一些bytes,造成此流接下来读取时缺少部分bytes<br>
|
||||
* 因此如果想复用此流,流需支持{@link InputStream#reset()}方法。
|
||||
*
|
||||
* @param in {@link InputStream}
|
||||
* @param isExact 是否精确匹配,如果为false,使用前64个bytes匹配,如果为true,使用前8192bytes匹配
|
||||
* @return 类型,文件的扩展名,未找到为{@code null}
|
||||
* @return 类型,文件的扩展名,提供的in为{@code null}或未找到为{@code null}
|
||||
* @throws IORuntimeException 读取流引起的异常
|
||||
*/
|
||||
public static String getType(InputStream in, boolean isExact) throws IORuntimeException {
|
||||
if (null == in) {
|
||||
return null;
|
||||
}
|
||||
return isExact
|
||||
? getType(IoUtil.readHex8192Upper(in))
|
||||
: getType(IoUtil.readHex64Upper(in));
|
||||
@ -94,6 +98,7 @@ public class FileTypeUtil {
|
||||
* 根据文件流的头部信息获得文件类型<br>
|
||||
* 注意此方法会读取头部64个bytes,造成此流接下来读取时缺少部分bytes<br>
|
||||
* 因此如果想复用此流,流需支持{@link InputStream#reset()}方法。
|
||||
*
|
||||
* @param in {@link InputStream}
|
||||
* @return 类型,文件的扩展名,未找到为{@code null}
|
||||
* @throws IORuntimeException 读取流引起的异常
|
||||
@ -132,6 +137,7 @@ public class FileTypeUtil {
|
||||
* 2、xls、doc、msi头信息无法区分,按照扩展名区分
|
||||
* 3、zip可能为docx、xlsx、pptx、jar、war、ofd头信息无法区分,按照扩展名区分
|
||||
* </pre>
|
||||
*
|
||||
* @param in {@link InputStream}
|
||||
* @param filename 文件名
|
||||
* @param isExact 是否精确匹配,如果为false,使用前64个bytes匹配,如果为true,使用前8192bytes匹配
|
||||
|
Loading…
x
Reference in New Issue
Block a user