mirror of
https://github.com/jeecgboot/JeecgBoot.git
synced 2026-04-23 02:10:32 +00:00
Close InputStream in parse
This commit is contained in:
parent
cf7eeac6ab
commit
f8791bb885
@ -73,24 +73,25 @@ public class TikaDocumentParser {
|
|||||||
AssertUtils.assertNotEmpty("请选择文件", file);
|
AssertUtils.assertNotEmpty("请选择文件", file);
|
||||||
try {
|
try {
|
||||||
// 用于解析(使用FileInputStream避免file.toPath()在Linux非UTF-8环境下中文文件名报错)
|
// 用于解析(使用FileInputStream避免file.toPath()在Linux非UTF-8环境下中文文件名报错)
|
||||||
InputStream isForParsing = new FileInputStream(file);
|
try (InputStream isForParsing = new FileInputStream(file)) {
|
||||||
// 使用 Tika 自动检测 MIME 类型
|
// 使用 Tika 自动检测 MIME 类型
|
||||||
String fileName = file.getName().toLowerCase();
|
String fileName = file.getName().toLowerCase();
|
||||||
//后缀
|
//后缀
|
||||||
String ext = FilenameUtils.getExtension(fileName);
|
String ext = FilenameUtils.getExtension(fileName);
|
||||||
if (fileName.endsWith(".txt")
|
if (fileName.endsWith(".txt")
|
||||||
|| fileName.endsWith(".md")
|
|| fileName.endsWith(".md")
|
||||||
|| fileName.endsWith(".pdf")) {
|
|| fileName.endsWith(".pdf")) {
|
||||||
return extractByTika(isForParsing);
|
return extractByTika(isForParsing);
|
||||||
//update-begin---author:wangshuai---date:2026-01-09---for:【QQYUN-14261】【AI】AI助手,支持多模态能力- 文档---
|
//update-begin---author:wangshuai---date:2026-01-09---for:【QQYUN-14261】【AI】AI助手,支持多模态能力- 文档---
|
||||||
} else if (FILE_SUFFIX.contains(ext.toLowerCase())) {
|
} else if (FILE_SUFFIX.contains(ext.toLowerCase())) {
|
||||||
return parseDocExcelPdfUsingApachePoi(file);
|
return parseDocExcelPdfUsingApachePoi(file);
|
||||||
//update-end---author:wangshuai---date:2026-01-09---for:【QQYUN-14261】【AI】AI助手,支持多模态能力- 文档---
|
//update-end---author:wangshuai---date:2026-01-09---for:【QQYUN-14261】【AI】AI助手,支持多模态能力- 文档---
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("不支持的文件格式: " + FilenameUtils.getExtension(fileName));
|
throw new IllegalArgumentException("不支持的文件格式: " + FilenameUtils.getExtension(fileName));
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user