修复PathUtil.getMimeType可能造成的异常

This commit is contained in:
Looly 2023-06-29 09:23:49 +08:00
parent e8adf37407
commit 824bf11d05
2 changed files with 9 additions and 2 deletions

View File

@ -594,8 +594,9 @@ public class PathUtil {
public static String getMimeType(final Path file) { public static String getMimeType(final Path file) {
try { try {
return Files.probeContentType(file); return Files.probeContentType(file);
} catch (final IOException e) { } catch (final IOException ignore) {
throw new IORuntimeException(e); // issue#3179使用OpenJDK可能抛出NoSuchFileException此处返回null
return null;
} }
} }

View File

@ -93,4 +93,10 @@ public class PathUtilTest {
public void moveTest2(){ public void moveTest2(){
PathUtil.move(Paths.get("D:\\project\\test1.txt"), Paths.get("D:\\project\\test2.txt"), false); PathUtil.move(Paths.get("D:\\project\\test1.txt"), Paths.get("D:\\project\\test2.txt"), false);
} }
@Test
public void issue3179Test() {
final String mimeType = PathUtil.getMimeType(Paths.get("xxxx.jpg"));
Assertions.assertEquals("image/jpeg", mimeType);
}
} }