mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
add test
This commit is contained in:
parent
73cf56f3a2
commit
7af3344b5e
@ -1,5 +1,7 @@
|
|||||||
package cn.hutool.core.io;
|
package cn.hutool.core.io;
|
||||||
|
|
||||||
|
import cn.hutool.core.lang.Console;
|
||||||
|
import cn.hutool.core.map.MapUtil;
|
||||||
import cn.hutool.core.util.HexUtil;
|
import cn.hutool.core.util.HexUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
|
||||||
@ -50,11 +52,13 @@ public class FileTypeUtil {
|
|||||||
* @return 文件类型,未找到为{@code null}
|
* @return 文件类型,未找到为{@code null}
|
||||||
*/
|
*/
|
||||||
public static String getType(String fileStreamHexHead) {
|
public static String getType(String fileStreamHexHead) {
|
||||||
for (Entry<String, String> fileTypeEntry : FILE_TYPE_MAP.entrySet()) {
|
if(MapUtil.isNotEmpty(FILE_TYPE_MAP)){
|
||||||
|
for (final Entry<String, String> fileTypeEntry : FILE_TYPE_MAP.entrySet()) {
|
||||||
if (StrUtil.startWithIgnoreCase(fileStreamHexHead, fileTypeEntry.getKey())) {
|
if (StrUtil.startWithIgnoreCase(fileStreamHexHead, fileTypeEntry.getKey())) {
|
||||||
return fileTypeEntry.getValue();
|
return fileTypeEntry.getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
byte[] bytes = (HexUtil.decodeHex(fileStreamHexHead));
|
byte[] bytes = (HexUtil.decodeHex(fileStreamHexHead));
|
||||||
return FileMagicNumber.getMagicNumber(bytes).getExtension();
|
return FileMagicNumber.getMagicNumber(bytes).getExtension();
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,7 @@ import org.junit.Assert;
|
|||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.*;
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件类型判断单元测试
|
* 文件类型判断单元测试
|
||||||
@ -92,4 +90,10 @@ public class FileTypeUtilTest {
|
|||||||
Assert.assertEquals("txt", type);
|
Assert.assertEquals("txt", type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Ignore
|
||||||
|
public void issue3024Test() {
|
||||||
|
String x = FileTypeUtil.getType(FileUtil.getInputStream("d:/test/TEST_WPS_DOC.doc"),true);
|
||||||
|
System.out.println(x);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user