mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
add null check
This commit is contained in:
parent
6f4a115032
commit
5f88089e4e
@ -90,9 +90,12 @@ public class HexUtil {
|
|||||||
*
|
*
|
||||||
* @param data byte[]
|
* @param data byte[]
|
||||||
* @param toLowerCase {@code true} 传换成小写格式 , {@code false} 传换成大写格式
|
* @param toLowerCase {@code true} 传换成小写格式 , {@code false} 传换成大写格式
|
||||||
* @return 十六进制char[]
|
* @return 十六进制char[]。如果提供的data为{@code null},返回{@code null}
|
||||||
*/
|
*/
|
||||||
public static char[] encodeHex(final byte[] data, final boolean toLowerCase) {
|
public static char[] encodeHex(final byte[] data, final boolean toLowerCase) {
|
||||||
|
if(null == data){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return (toLowerCase ? Base16Codec.CODEC_LOWER : Base16Codec.CODEC_UPPER).encode(data);
|
return (toLowerCase ? Base16Codec.CODEC_LOWER : Base16Codec.CODEC_UPPER).encode(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +138,7 @@ public class HexUtil {
|
|||||||
* @return 十六进制String
|
* @return 十六进制String
|
||||||
*/
|
*/
|
||||||
public static String encodeHexStr(final byte[] data, final boolean toLowerCase) {
|
public static String encodeHexStr(final byte[] data, final boolean toLowerCase) {
|
||||||
return new String(encodeHex(data, toLowerCase));
|
return StrUtil.str(encodeHex(data, toLowerCase), CharsetUtil.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------------------- decode
|
// ---------------------------------------------------------------------------------------------------- decode
|
||||||
|
@ -91,12 +91,16 @@ public class FileTypeUtil {
|
|||||||
* 根据文件流的头部信息获得文件类型<br>
|
* 根据文件流的头部信息获得文件类型<br>
|
||||||
* 注意此方法会读取头部一些bytes,造成此流接下来读取时缺少部分bytes<br>
|
* 注意此方法会读取头部一些bytes,造成此流接下来读取时缺少部分bytes<br>
|
||||||
* 因此如果想复用此流,流需支持{@link InputStream#reset()}方法。
|
* 因此如果想复用此流,流需支持{@link InputStream#reset()}方法。
|
||||||
|
*
|
||||||
* @param in {@link InputStream}
|
* @param in {@link InputStream}
|
||||||
* @param isExact 是否精确匹配,如果为false,使用前64个bytes匹配,如果为true,使用前8192bytes匹配
|
* @param isExact 是否精确匹配,如果为false,使用前64个bytes匹配,如果为true,使用前8192bytes匹配
|
||||||
* @return 类型,文件的扩展名,未找到为{@code null}
|
* @return 类型,文件的扩展名,in为{@code null}或未找到为{@code null}
|
||||||
* @throws IORuntimeException 读取流引起的异常
|
* @throws IORuntimeException 读取流引起的异常
|
||||||
*/
|
*/
|
||||||
public static String getType(final InputStream in, final boolean isExact) throws IORuntimeException {
|
public static String getType(final InputStream in, final boolean isExact) throws IORuntimeException {
|
||||||
|
if (null == in) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return isExact
|
return isExact
|
||||||
? getType(readHex8192Upper(in))
|
? getType(readHex8192Upper(in))
|
||||||
: getType(readHex64Upper(in));
|
: getType(readHex64Upper(in));
|
||||||
@ -106,6 +110,7 @@ public class FileTypeUtil {
|
|||||||
* 根据文件流的头部信息获得文件类型<br>
|
* 根据文件流的头部信息获得文件类型<br>
|
||||||
* 注意此方法会读取头部64个bytes,造成此流接下来读取时缺少部分bytes<br>
|
* 注意此方法会读取头部64个bytes,造成此流接下来读取时缺少部分bytes<br>
|
||||||
* 因此如果想复用此流,流需支持{@link InputStream#reset()}方法。
|
* 因此如果想复用此流,流需支持{@link InputStream#reset()}方法。
|
||||||
|
*
|
||||||
* @param in {@link InputStream}
|
* @param in {@link InputStream}
|
||||||
* @return 类型,文件的扩展名,未找到为{@code null}
|
* @return 类型,文件的扩展名,未找到为{@code null}
|
||||||
* @throws IORuntimeException 读取流引起的异常
|
* @throws IORuntimeException 读取流引起的异常
|
||||||
@ -144,6 +149,7 @@ public class FileTypeUtil {
|
|||||||
* 2、xls、doc、msi头信息无法区分,按照扩展名区分
|
* 2、xls、doc、msi头信息无法区分,按照扩展名区分
|
||||||
* 3、zip可能为docx、xlsx、pptx、jar、war、ofd头信息无法区分,按照扩展名区分
|
* 3、zip可能为docx、xlsx、pptx、jar、war、ofd头信息无法区分,按照扩展名区分
|
||||||
* </pre>
|
* </pre>
|
||||||
|
*
|
||||||
* @param in {@link InputStream}
|
* @param in {@link InputStream}
|
||||||
* @param filename 文件名
|
* @param filename 文件名
|
||||||
* @param isExact 是否精确匹配,如果为false,使用前64个bytes匹配,如果为true,使用前8192bytes匹配
|
* @param isExact 是否精确匹配,如果为false,使用前64个bytes匹配,如果为true,使用前8192bytes匹配
|
||||||
|
Loading…
x
Reference in New Issue
Block a user