Browse Source

feat-优化类型判断:无法通过后缀名判断文件类型时,直接通过魔法数判断。

pull/3829/head
Black Pan 8 months ago
parent
commit
9c48e4696d
  1. 10
      easyexcel-core/src/main/java/com/alibaba/excel/support/ExcelTypeEnum.java

10
easyexcel-core/src/main/java/com/alibaba/excel/support/ExcelTypeEnum.java

@ -59,12 +59,6 @@ public enum ExcelTypeEnum {
if (!file.exists()) {
throw new ExcelAnalysisException("File " + file.getAbsolutePath() + " not exists.");
}
// If there is a password, use the FileMagic first
if (!StringUtils.isEmpty(readWorkbook.getPassword())) {
try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file))) {
return recognitionExcelType(bufferedInputStream);
}
}
// Use the name to determine the type
String fileName = file.getName();
if (fileName.endsWith(XLSX.getValue())) {
@ -74,6 +68,10 @@ public enum ExcelTypeEnum {
} else if (fileName.endsWith(CSV.getValue())) {
return CSV;
}
//If cannot get the name, use the magic number to determine the type
try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file))) {
return recognitionExcelType(bufferedInputStream);
}
}
if (!inputStream.markSupported()) {
inputStream = new BufferedInputStream(inputStream);

Loading…
Cancel
Save