Skip to content

Commit d48507a

Browse files
Merge pull request #9548 from tejasae-afk/fix/close-inputstream-in-parse
Close InputStream in parse
2 parents e38713f + f8791bb commit d48507a

File tree

1 file changed

+18
-17
lines changed
  • jeecg-boot/jeecg-boot-module/jeecg-boot-module-airag/src/main/java/org/jeecg/modules/airag/llm/document

1 file changed

+18
-17
lines changed

jeecg-boot/jeecg-boot-module/jeecg-boot-module-airag/src/main/java/org/jeecg/modules/airag/llm/document/TikaDocumentParser.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,25 @@ public Document parse(File file) {
7373
AssertUtils.assertNotEmpty("请选择文件", file);
7474
try {
7575
// 用于解析(使用FileInputStream避免file.toPath()在Linux非UTF-8环境下中文文件名报错)
76-
InputStream isForParsing = new FileInputStream(file);
77-
// 使用 Tika 自动检测 MIME 类型
78-
String fileName = file.getName().toLowerCase();
79-
//后缀
80-
String ext = FilenameUtils.getExtension(fileName);
81-
if (fileName.endsWith(".txt")
82-
|| fileName.endsWith(".md")
83-
|| fileName.endsWith(".pdf")) {
84-
return extractByTika(isForParsing);
85-
//update-begin---author:wangshuai---date:2026-01-09---for:【QQYUN-14261】【AI】AI助手,支持多模态能力- 文档---
86-
} else if (FILE_SUFFIX.contains(ext.toLowerCase())) {
87-
return parseDocExcelPdfUsingApachePoi(file);
88-
//update-end---author:wangshuai---date:2026-01-09---for:【QQYUN-14261】【AI】AI助手,支持多模态能力- 文档---
89-
} else {
90-
throw new IllegalArgumentException("不支持的文件格式: " + FilenameUtils.getExtension(fileName));
76+
try (InputStream isForParsing = new FileInputStream(file)) {
77+
// 使用 Tika 自动检测 MIME 类型
78+
String fileName = file.getName().toLowerCase();
79+
//后缀
80+
String ext = FilenameUtils.getExtension(fileName);
81+
if (fileName.endsWith(".txt")
82+
|| fileName.endsWith(".md")
83+
|| fileName.endsWith(".pdf")) {
84+
return extractByTika(isForParsing);
85+
//update-begin---author:wangshuai---date:2026-01-09---for:【QQYUN-14261】【AI】AI助手,支持多模态能力- 文档---
86+
} else if (FILE_SUFFIX.contains(ext.toLowerCase())) {
87+
return parseDocExcelPdfUsingApachePoi(file);
88+
//update-end---author:wangshuai---date:2026-01-09---for:【QQYUN-14261】【AI】AI助手,支持多模态能力- 文档---
89+
} else {
90+
throw new IllegalArgumentException("不支持的文件格式: " + FilenameUtils.getExtension(fileName));
91+
}
92+
} catch (IOException e) {
93+
throw new RuntimeException(e);
9194
}
92-
} catch (IOException e) {
93-
throw new RuntimeException(e);
9495
}
9596
}
9697

0 commit comments

Comments
 (0)