fix:修复抽取空文件内容报错

This commit is contained in:
2023-05-25 14:57:50 +08:00
parent 8d3b39e9e3
commit 04a3d4237a
@@ -5,11 +5,11 @@ import java.io.FileInputStream;
import java.io.IOException;
import com.adc.da.report.constant.ReportConstants;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hslf.usermodel.HSLFShape;
import org.apache.poi.hslf.usermodel.HSLFSlide;
import org.apache.poi.hslf.usermodel.HSLFTextShape;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
@@ -22,7 +22,6 @@ import org.apache.poi.hwpf.extractor.WordExtractor;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.hslf.extractor.PowerPointExtractor;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;
@@ -31,6 +30,7 @@ import org.apache.pdfbox.text.PDFTextStripper;
*
* @author caihaohan
*/
@Slf4j
public class FileContentUtil {
public static String readFileContent(File file) throws IOException {
@@ -39,7 +39,7 @@ public class FileContentUtil {
StringBuilder content = new StringBuilder();
FileInputStream fis = new FileInputStream(file);
try {
switch (fileExtension) {
case ReportConstants.FILE_EXTENSIONS_XLS:
HSSFWorkbook workbookXls = new HSSFWorkbook(fis);
@@ -87,7 +87,10 @@ public class FileContentUtil {
content = new StringBuilder(stripper.getText(document));
default:
}
} catch (Exception e) {
fis.close();
log.info("文件内容抽取失败,原因可能是上传的文件为空文件");
}
return content.toString();
}