cos下载流关闭处理

This commit is contained in:
liyawei
2022-06-16 14:25:49 +08:00
parent dd6168c739
commit e0ff4ee573
7 changed files with 191 additions and 169 deletions
@@ -615,13 +615,17 @@ public class ParamsInfoEOServiceImpl extends ServiceImpl<ParamsInfoEOMapper, Par
return sheetsList; return sheetsList;
} }
private void downLoadFileList(List<OSSFile> fileTemplateList,String fileNowPath) throws IOException { private void downLoadFileList(List<OSSFile> fileTemplateList,String fileNowPath) {
for(OSSFile fileExportDto : fileTemplateList){ for(OSSFile fileExportDto : fileTemplateList){
String oldPath = fileExportDto.getUrl(); String oldPath = fileExportDto.getUrl();
String newPath = fileNowPath + File.separator + fileExportDto.getFileName(); String newPath = fileNowPath + File.separator + fileExportDto.getFileName();
if (CosBootUtil.doesObjectExist(oldPath)){ if (CosBootUtil.doesObjectExist(oldPath)){
InputStream in = CosBootUtil.download(oldPath); try (InputStream in = CosBootUtil.download(oldPath);) {
copyFile(in, newPath); copyFile(in, newPath);
} catch (IOException e) {
e.printStackTrace();
log.error(e.getMessage(), e);
}
} }
} }
} }
@@ -4439,6 +4439,8 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
throw new IOException("复制文件失败!"); throw new IOException("复制文件失败!");
} finally {
in.close();
} }
} }
// public static void copyFile(String oldFile, String newFile) throws IOException { // public static void copyFile(String oldFile, String newFile) throws IOException {
@@ -18,8 +18,8 @@ public class ReadPdfUtil {
public static String readPdf(String path) { public static String readPdf(String path) {
if(CosBootUtil.doesObjectExist(path)){ if(CosBootUtil.doesObjectExist(path)){
InputStream in = CosBootUtil.download(path); try (InputStream in = CosBootUtil.download(path);
try (PDDocument document = PDDocument.load(in)) { PDDocument document = PDDocument.load(in)) {
document.getClass(); document.getClass();
// if(!document.isEncrypted()) { // if(!document.isEncrypted()) {
PDFTextStripperByArea stripper = new PDFTextStripperByArea(); PDFTextStripperByArea stripper = new PDFTextStripperByArea();
@@ -31,6 +31,7 @@ public class ReadWordUtil {
WordExtractor ex = new WordExtractor(in); WordExtractor ex = new WordExtractor(in);
str = ex.getText(); str = ex.getText();
ex.close(); ex.close();
in.close();
} }
} else if (path.endsWith("docx")) { } else if (path.endsWith("docx")) {
//先把文件存到本地, 用完后在删除 //先把文件存到本地, 用完后在删除
@@ -52,6 +53,7 @@ public class ReadWordUtil {
str = extractor.getText().trim(); str = extractor.getText().trim();
extractor.close(); extractor.close();
fileTemp.delete(); fileTemp.delete();
in.close();
} }
} else { } else {
throw new JeroBootException("此文件不是word文件"); throw new JeroBootException("此文件不是word文件");
@@ -188,15 +188,14 @@ public class OcrRestfulController{
String fileOriPath = ossFile.getUrl(); String fileOriPath = ossFile.getUrl();
String oriName = ossFile.getFileName(); String oriName = ossFile.getFileName();
try { if (!CosBootUtil.doesObjectExist(fileOriPath)) {
if (!CosBootUtil.doesObjectExist(fileOriPath)) { if (CutEnum.CN.getValue().equals(ocrRecordEO.getCut())) {
if (CutEnum.CN.getValue().equals(ocrRecordEO.getCut())) { return Result.error("无法找到该文件");
return Result.error("无法找到该文件"); } else {
} else { return Result.error("File not found");
return Result.error("File not found");
}
} }
InputStream fileInputStream = CosBootUtil.download(fileOriPath); }
try (InputStream fileInputStream = CosBootUtil.download(fileOriPath);) {
MultipartFile multipartFile = new MockMultipartFile(oriName, oriName, MultipartFile multipartFile = new MockMultipartFile(oriName, oriName,
ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream); ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream);
return ocrRestfulService.handleFile(multipartFile,multipartFile.getOriginalFilename(),ocrRecordEO,"add"); return ocrRestfulService.handleFile(multipartFile,multipartFile.getOriginalFilename(),ocrRecordEO,"add");
@@ -119,34 +119,34 @@ public class FileSpiltService {
// } else { // } else {
// nowStart.add(String.valueOf(sarFileSplitInfoEO.getStartNumber())); // nowStart.add(String.valueOf(sarFileSplitInfoEO.getStartNumber()));
// } // }
try { //获取文件地址
//获取文件地址 String connectId = sarFileSplitInfoEO.getConnectId();
String connectId = sarFileSplitInfoEO.getConnectId(); String fileName = sarFileSplitInfoEO.getFileName();
String fileName = sarFileSplitInfoEO.getFileName(); if (StringUtils.isEmpty(connectId) || StringUtils.isEmpty(fileName)) {
if (StringUtils.isEmpty(connectId) || StringUtils.isEmpty(fileName)) { throw new JeroBootException("当前文件未找到,请重新选择!");
throw new JeroBootException("当前文件未找到,请重新选择!"); }
} LambdaQueryWrapper<OSSFile> queryWrapper = new LambdaQueryWrapper();
LambdaQueryWrapper<OSSFile> queryWrapper = new LambdaQueryWrapper(); queryWrapper.eq(OSSFile::getConnectId, connectId);
queryWrapper.eq(OSSFile::getConnectId, connectId); queryWrapper.eq(OSSFile::getFileName, fileName);
queryWrapper.eq(OSSFile::getFileName, fileName); queryWrapper.orderByDesc(OSSFile::getCreateTime);
queryWrapper.orderByDesc(OSSFile::getCreateTime); List<OSSFile> ossFileList = iossFileService.list(queryWrapper);
List<OSSFile> ossFileList = iossFileService.list(queryWrapper); if (CollectionUtils.isEmpty(ossFileList)) {
if (CollectionUtils.isEmpty(ossFileList)) { throw new JeroBootException("当前文件未找到,请重新选择!");
throw new JeroBootException("当前文件未找到,请重新选择!"); }
} OSSFile ossFile = ossFileList.get(0);
OSSFile ossFile = ossFileList.get(0);
String readFilePath = ossFile.getUrl(); String readFilePath = ossFile.getUrl();
if (StringUtils.isEmpty(readFilePath) || !CosBootUtil.doesObjectExist(readFilePath)) { if (StringUtils.isEmpty(readFilePath) || !CosBootUtil.doesObjectExist(readFilePath)) {
throw new JeroBootException("当前文件未找到,请重新选择!"); throw new JeroBootException("当前文件未找到,请重新选择!");
} }
try (InputStream is = CosBootUtil.download(readFilePath);) {
// AttFileEO attFileEO = attFileEOService.getFileInfo(sarFileSplitInfoEO.getAttId()); // AttFileEO attFileEO = attFileEOService.getFileInfo(sarFileSplitInfoEO.getAttId());
// String readFilePath = filePath + "/" + attFileEO.getFilePath() + attFileEO.getFileName(); // String readFilePath = filePath + "/" + attFileEO.getFilePath() + attFileEO.getFileName();
// String readFilePath = "C:\\Users\\wangc\\Desktop\\蔚来演示数据\\GB 11551-2014 汽车正面碰撞的乘员保护.docx"; // String readFilePath = "C:\\Users\\wangc\\Desktop\\蔚来演示数据\\GB 11551-2014 汽车正面碰撞的乘员保护.docx";
// InputStream is = new FileInputStream(readFilePath); //需要将文件路更改为word文档所在路径。 // InputStream is = new FileInputStream(readFilePath); //需要将文件路更改为word文档所在路径。
InputStream is = CosBootUtil.download(readFilePath); //需要将文件路更改为word文档所在路径。
XWPFDocument doc = new XWPFDocument(is); XWPFDocument doc = new XWPFDocument(is);
Pattern ptest = Pattern.compile("^1范围"); Pattern ptest = Pattern.compile("^1范围");
@@ -642,27 +642,27 @@ public class FileSpiltService {
// } else { // } else {
// nowStart.add(String.valueOf(sarFileSplitInfoEO.getStartNumber())); // nowStart.add(String.valueOf(sarFileSplitInfoEO.getStartNumber()));
// } // }
try { //获取文件地址
//获取文件地址 String connectId = sarFileSplitInfoEO.getConnectId();
String connectId = sarFileSplitInfoEO.getConnectId(); String fileName = sarFileSplitInfoEO.getFileName();
String fileName = sarFileSplitInfoEO.getFileName(); if (StringUtils.isEmpty(connectId) || StringUtils.isEmpty(fileName)) {
if (StringUtils.isEmpty(connectId) || StringUtils.isEmpty(fileName)) { throw new JeroBootException("当前文件未找到,请重新选择!");
throw new JeroBootException("当前文件未找到,请重新选择!"); }
} LambdaQueryWrapper<OSSFile> queryWrapper = new LambdaQueryWrapper();
LambdaQueryWrapper<OSSFile> queryWrapper = new LambdaQueryWrapper(); queryWrapper.eq(OSSFile::getConnectId, connectId);
queryWrapper.eq(OSSFile::getConnectId, connectId); queryWrapper.eq(OSSFile::getFileName, fileName);
queryWrapper.eq(OSSFile::getFileName, fileName); queryWrapper.orderByDesc(OSSFile::getCreateTime);
queryWrapper.orderByDesc(OSSFile::getCreateTime); List<OSSFile> ossFileList = iossFileService.list(queryWrapper);
List<OSSFile> ossFileList = iossFileService.list(queryWrapper); if (CollectionUtils.isEmpty(ossFileList)) {
if (CollectionUtils.isEmpty(ossFileList)) { throw new JeroBootException("当前文件未找到,请重新选择!");
throw new JeroBootException("当前文件未找到,请重新选择!"); }
} OSSFile ossFile = ossFileList.get(0);
OSSFile ossFile = ossFileList.get(0); String readFilePath = ossFile.getUrl();
String readFilePath = ossFile.getUrl(); if (StringUtils.isEmpty(readFilePath) || !CosBootUtil.doesObjectExist(readFilePath)) {
if (StringUtils.isEmpty(readFilePath) || !CosBootUtil.doesObjectExist(readFilePath)) { throw new JeroBootException("当前文件未找到,请重新选择!");
throw new JeroBootException("当前文件未找到,请重新选择!"); }
} try (InputStream is = CosBootUtil.download(readFilePath);) {
InputStream is = CosBootUtil.download(readFilePath);
// InputStream is = new FileInputStream(readFilePath); //需要将文件路更改为word文档所在路径。 // InputStream is = new FileInputStream(readFilePath); //需要将文件路更改为word文档所在路径。
XWPFDocument doc = new XWPFDocument(is); XWPFDocument doc = new XWPFDocument(is);
@@ -824,27 +824,27 @@ public class FileSpiltService {
// } else { // } else {
// nowStart.add(String.valueOf(sarFileSplitInfoEO.getStartNumber())); // nowStart.add(String.valueOf(sarFileSplitInfoEO.getStartNumber()));
// } // }
try { //获取文件地址
//获取文件地址 String connectId = sarFileSplitInfoEO.getConnectId();
String connectId = sarFileSplitInfoEO.getConnectId(); String fileName = sarFileSplitInfoEO.getFileName();
String fileName = sarFileSplitInfoEO.getFileName(); if (StringUtils.isEmpty(connectId) || StringUtils.isEmpty(fileName)) {
if (StringUtils.isEmpty(connectId) || StringUtils.isEmpty(fileName)) { throw new JeroBootException("当前文件未找到,请重新选择!");
throw new JeroBootException("当前文件未找到,请重新选择!"); }
} LambdaQueryWrapper<OSSFile> queryWrapper = new LambdaQueryWrapper();
LambdaQueryWrapper<OSSFile> queryWrapper = new LambdaQueryWrapper(); queryWrapper.eq(OSSFile::getConnectId, connectId);
queryWrapper.eq(OSSFile::getConnectId, connectId); queryWrapper.eq(OSSFile::getFileName, fileName);
queryWrapper.eq(OSSFile::getFileName, fileName); queryWrapper.orderByDesc(OSSFile::getCreateTime);
queryWrapper.orderByDesc(OSSFile::getCreateTime); List<OSSFile> ossFileList = iossFileService.list(queryWrapper);
List<OSSFile> ossFileList = iossFileService.list(queryWrapper); if (CollectionUtils.isEmpty(ossFileList)) {
if (CollectionUtils.isEmpty(ossFileList)) { throw new JeroBootException("当前文件未找到,请重新选择!");
throw new JeroBootException("当前文件未找到,请重新选择!"); }
} OSSFile ossFile = ossFileList.get(0);
OSSFile ossFile = ossFileList.get(0); String readFilePath = ossFile.getUrl();
String readFilePath = ossFile.getUrl(); if (StringUtils.isEmpty(readFilePath) || !CosBootUtil.doesObjectExist(readFilePath)) {
if (StringUtils.isEmpty(readFilePath) || !CosBootUtil.doesObjectExist(readFilePath)) { throw new JeroBootException("当前文件未找到,请重新选择!");
throw new JeroBootException("当前文件未找到,请重新选择!"); }
} try (InputStream is = CosBootUtil.download(readFilePath);) {
InputStream is = CosBootUtil.download(readFilePath);
// InputStream is = new FileInputStream(readFilePath); //需要将文件路更改为word文档所在路径。 // InputStream is = new FileInputStream(readFilePath); //需要将文件路更改为word文档所在路径。
XWPFDocument doc = new XWPFDocument(is); XWPFDocument doc = new XWPFDocument(is);
@@ -1013,27 +1013,27 @@ public class FileSpiltService {
// } else { // } else {
// nowStart.add(String.valueOf(sarFileSplitInfoEO.getStartNumber())); // nowStart.add(String.valueOf(sarFileSplitInfoEO.getStartNumber()));
// } // }
try { //获取文件地址
//获取文件地址 String connectId = sarFileSplitInfoEO.getConnectId();
String connectId = sarFileSplitInfoEO.getConnectId(); String fileName = sarFileSplitInfoEO.getFileName();
String fileName = sarFileSplitInfoEO.getFileName(); if (StringUtils.isEmpty(connectId) || StringUtils.isEmpty(fileName)) {
if (StringUtils.isEmpty(connectId) || StringUtils.isEmpty(fileName)) { throw new JeroBootException("当前文件未找到,请重新选择!");
throw new JeroBootException("当前文件未找到,请重新选择!"); }
} LambdaQueryWrapper<OSSFile> queryWrapper = new LambdaQueryWrapper();
LambdaQueryWrapper<OSSFile> queryWrapper = new LambdaQueryWrapper(); queryWrapper.eq(OSSFile::getConnectId, connectId);
queryWrapper.eq(OSSFile::getConnectId, connectId); queryWrapper.eq(OSSFile::getFileName, fileName);
queryWrapper.eq(OSSFile::getFileName, fileName); queryWrapper.orderByDesc(OSSFile::getCreateTime);
queryWrapper.orderByDesc(OSSFile::getCreateTime); List<OSSFile> ossFileList = iossFileService.list(queryWrapper);
List<OSSFile> ossFileList = iossFileService.list(queryWrapper); if (CollectionUtils.isEmpty(ossFileList)) {
if (CollectionUtils.isEmpty(ossFileList)) { throw new JeroBootException("当前文件未找到,请重新选择!");
throw new JeroBootException("当前文件未找到,请重新选择!"); }
} OSSFile ossFile = ossFileList.get(0);
OSSFile ossFile = ossFileList.get(0); String readFilePath = ossFile.getUrl();
String readFilePath = ossFile.getUrl(); if (StringUtils.isEmpty(readFilePath) || !CosBootUtil.doesObjectExist(readFilePath)) {
if (StringUtils.isEmpty(readFilePath) || !CosBootUtil.doesObjectExist(readFilePath)) { throw new JeroBootException("当前文件未找到,请重新选择!");
throw new JeroBootException("当前文件未找到,请重新选择!"); }
} try (InputStream is = CosBootUtil.download(readFilePath);) {
InputStream is = CosBootUtil.download(readFilePath);
// InputStream is = new FileInputStream(readFilePath); //需要将文件路更改为word文档所在路径。 // InputStream is = new FileInputStream(readFilePath); //需要将文件路更改为word文档所在路径。
XWPFDocument doc = new XWPFDocument(is); XWPFDocument doc = new XWPFDocument(is);
@@ -1200,27 +1200,27 @@ public class FileSpiltService {
// } else { // } else {
// nowStart.add(String.valueOf(sarFileSplitInfoEO.getStartNumber())); // nowStart.add(String.valueOf(sarFileSplitInfoEO.getStartNumber()));
// } // }
try { //获取文件地址
//获取文件地址 String connectId = sarFileSplitInfoEO.getConnectId();
String connectId = sarFileSplitInfoEO.getConnectId(); String fileName = sarFileSplitInfoEO.getFileName();
String fileName = sarFileSplitInfoEO.getFileName(); if (StringUtils.isEmpty(connectId) || StringUtils.isEmpty(fileName)) {
if (StringUtils.isEmpty(connectId) || StringUtils.isEmpty(fileName)) { throw new JeroBootException("当前文件未找到,请重新选择!");
throw new JeroBootException("当前文件未找到,请重新选择!"); }
} LambdaQueryWrapper<OSSFile> queryWrapper = new LambdaQueryWrapper();
LambdaQueryWrapper<OSSFile> queryWrapper = new LambdaQueryWrapper(); queryWrapper.eq(OSSFile::getConnectId, connectId);
queryWrapper.eq(OSSFile::getConnectId, connectId); queryWrapper.eq(OSSFile::getFileName, fileName);
queryWrapper.eq(OSSFile::getFileName, fileName); queryWrapper.orderByDesc(OSSFile::getCreateTime);
queryWrapper.orderByDesc(OSSFile::getCreateTime); List<OSSFile> ossFileList = iossFileService.list(queryWrapper);
List<OSSFile> ossFileList = iossFileService.list(queryWrapper); if (CollectionUtils.isEmpty(ossFileList)) {
if (CollectionUtils.isEmpty(ossFileList)) { throw new JeroBootException("当前文件未找到,请重新选择!");
throw new JeroBootException("当前文件未找到,请重新选择!"); }
} OSSFile ossFile = ossFileList.get(0);
OSSFile ossFile = ossFileList.get(0); String readFilePath = ossFile.getUrl();
String readFilePath = ossFile.getUrl(); if (StringUtils.isEmpty(readFilePath) || !CosBootUtil.doesObjectExist(readFilePath)) {
if (StringUtils.isEmpty(readFilePath) || !CosBootUtil.doesObjectExist(readFilePath)) { throw new JeroBootException("当前文件未找到,请重新选择!");
throw new JeroBootException("当前文件未找到,请重新选择!"); }
} try (InputStream is = CosBootUtil.download(readFilePath);) {
InputStream is = CosBootUtil.download(readFilePath);
// InputStream is = new FileInputStream(readFilePath); //需要将文件路更改为word文档所在路径。 // InputStream is = new FileInputStream(readFilePath); //需要将文件路更改为word文档所在路径。
XWPFDocument doc = new XWPFDocument(is); XWPFDocument doc = new XWPFDocument(is);
@@ -1377,27 +1377,27 @@ public class FileSpiltService {
// } else { // } else {
// nowStart.add(String.valueOf(sarFileSplitInfoEO.getStartNumber())); // nowStart.add(String.valueOf(sarFileSplitInfoEO.getStartNumber()));
// } // }
try { //获取文件地址
//获取文件地址 String connectId = sarFileSplitInfoEO.getConnectId();
String connectId = sarFileSplitInfoEO.getConnectId(); String fileName = sarFileSplitInfoEO.getFileName();
String fileName = sarFileSplitInfoEO.getFileName(); if (StringUtils.isEmpty(connectId) || StringUtils.isEmpty(fileName)) {
if (StringUtils.isEmpty(connectId) || StringUtils.isEmpty(fileName)) { throw new JeroBootException("当前文件未找到,请重新选择!");
throw new JeroBootException("当前文件未找到,请重新选择!"); }
} LambdaQueryWrapper<OSSFile> queryWrapper = new LambdaQueryWrapper();
LambdaQueryWrapper<OSSFile> queryWrapper = new LambdaQueryWrapper(); queryWrapper.eq(OSSFile::getConnectId, connectId);
queryWrapper.eq(OSSFile::getConnectId, connectId); queryWrapper.eq(OSSFile::getFileName, fileName);
queryWrapper.eq(OSSFile::getFileName, fileName); queryWrapper.orderByDesc(OSSFile::getCreateTime);
queryWrapper.orderByDesc(OSSFile::getCreateTime); List<OSSFile> ossFileList = iossFileService.list(queryWrapper);
List<OSSFile> ossFileList = iossFileService.list(queryWrapper); if (CollectionUtils.isEmpty(ossFileList)) {
if (CollectionUtils.isEmpty(ossFileList)) { throw new JeroBootException("当前文件未找到,请重新选择!");
throw new JeroBootException("当前文件未找到,请重新选择!"); }
} OSSFile ossFile = ossFileList.get(0);
OSSFile ossFile = ossFileList.get(0); String readFilePath = ossFile.getUrl();
String readFilePath = ossFile.getUrl(); if (StringUtils.isEmpty(readFilePath) || !CosBootUtil.doesObjectExist(readFilePath)) {
if (StringUtils.isEmpty(readFilePath) || !CosBootUtil.doesObjectExist(readFilePath)) { throw new JeroBootException("当前文件未找到,请重新选择!");
throw new JeroBootException("当前文件未找到,请重新选择!"); }
} try (InputStream is = CosBootUtil.download(readFilePath);){
InputStream is = CosBootUtil.download(readFilePath);
// InputStream is = new FileInputStream(readFilePath); //需要将文件路更改为word文档所在路径。 // InputStream is = new FileInputStream(readFilePath); //需要将文件路更改为word文档所在路径。
XWPFDocument doc = new XWPFDocument(is); XWPFDocument doc = new XWPFDocument(is);
@@ -1565,28 +1565,28 @@ public class FileSpiltService {
// } else { // } else {
// nowStart.add(String.valueOf(sarFileSplitInfoEO.getStartNumber())); // nowStart.add(String.valueOf(sarFileSplitInfoEO.getStartNumber()));
// } // }
try { //获取文件地址
//获取文件地址 String connectId = sarFileSplitInfoEO.getConnectId();
String connectId = sarFileSplitInfoEO.getConnectId(); String fileName = sarFileSplitInfoEO.getFileName();
String fileName = sarFileSplitInfoEO.getFileName(); if (StringUtils.isEmpty(connectId) || StringUtils.isEmpty(fileName)) {
if (StringUtils.isEmpty(connectId) || StringUtils.isEmpty(fileName)) { throw new JeroBootException("当前文件未找到,请重新选择!");
throw new JeroBootException("当前文件未找到,请重新选择!"); }
} LambdaQueryWrapper<OSSFile> queryWrapper = new LambdaQueryWrapper();
LambdaQueryWrapper<OSSFile> queryWrapper = new LambdaQueryWrapper(); queryWrapper.eq(OSSFile::getConnectId, connectId);
queryWrapper.eq(OSSFile::getConnectId, connectId); queryWrapper.eq(OSSFile::getFileName, fileName);
queryWrapper.eq(OSSFile::getFileName, fileName); queryWrapper.orderByDesc(OSSFile::getCreateTime);
queryWrapper.orderByDesc(OSSFile::getCreateTime); List<OSSFile> ossFileList = iossFileService.list(queryWrapper);
List<OSSFile> ossFileList = iossFileService.list(queryWrapper); if (CollectionUtils.isEmpty(ossFileList)) {
if (CollectionUtils.isEmpty(ossFileList)) { throw new JeroBootException("当前文件未找到,请重新选择!");
throw new JeroBootException("当前文件未找到,请重新选择!"); }
} OSSFile ossFile = ossFileList.get(0);
OSSFile ossFile = ossFileList.get(0); String readFilePath = ossFile.getUrl();
String readFilePath = ossFile.getUrl();
if (StringUtils.isEmpty(readFilePath) || !CosBootUtil.doesObjectExist(readFilePath)) {
throw new JeroBootException("当前文件未找到,请重新选择!");
}
try (InputStream is = CosBootUtil.download(readFilePath);){
if (StringUtils.isEmpty(readFilePath) || !CosBootUtil.doesObjectExist(readFilePath)) {
throw new JeroBootException("当前文件未找到,请重新选择!");
}
InputStream is = CosBootUtil.download(readFilePath);
// InputStream is = new FileInputStream(readFilePath); //需要将文件路更改为word文档所在路径。 // InputStream is = new FileInputStream(readFilePath); //需要将文件路更改为word文档所在路径。
XWPFDocument doc = new XWPFDocument(is); XWPFDocument doc = new XWPFDocument(is);
@@ -1652,9 +1652,14 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
throw new JeroBootException("Importing a compressed package that does not exist!"); throw new JeroBootException("Importing a compressed package that does not exist!");
} }
} }
InputStream inputStream = CosBootUtil.download(url); MultipartFile mFile = null;
String fileName = url.substring((url.lastIndexOf("/") + 1)); try (InputStream inputStream = CosBootUtil.download(url);) {
MultipartFile mFile = new MockMultipartFile(fileName, fileName, ContentType.APPLICATION_OCTET_STREAM.toString(), inputStream); String fileName = url.substring((url.lastIndexOf("/") + 1));
mFile = new MockMultipartFile(fileName, fileName, ContentType.APPLICATION_OCTET_STREAM.toString(), inputStream);
} catch (IOException e) {
e.printStackTrace();
log.error(e.getMessage(), e);
}
Result<?> result = importSplitItems(mFile, cut, menuId, infoId); Result<?> result = importSplitItems(mFile, cut, menuId, infoId);
if(!result.isSuccess()){ if(!result.isSuccess()){
@@ -3284,25 +3289,33 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
} }
public void downLoadImgList(List<FileSplitValImgExportDto> allImgList, String fileNowPath) throws IOException { public void downLoadImgList(List<FileSplitValImgExportDto> allImgList, String fileNowPath) {
for(FileSplitValImgExportDto imgExportDto : allImgList){ for(FileSplitValImgExportDto imgExportDto : allImgList){
String oldPath = imgExportDto.getImgPath(); String oldPath = imgExportDto.getImgPath();
String newPath = fileNowPath + File.separator + imgExportDto.getImgName(); String newPath = fileNowPath + File.separator + imgExportDto.getImgName();
if (CosBootUtil.doesObjectExist(oldPath)){ if (CosBootUtil.doesObjectExist(oldPath)){
InputStream in = CosBootUtil.download(oldPath); try (InputStream in = CosBootUtil.download(oldPath);) {
copyFile1(in, newPath); copyFile1(in, newPath);
} catch (IOException e) {
e.printStackTrace();
log.error(e.getMessage(), e);
}
} }
} }
} }
public void downLoadFileList(List<OSSFile> allRelevFileList,String fileNowPath) throws IOException { public void downLoadFileList(List<OSSFile> allRelevFileList,String fileNowPath) {
for(OSSFile fileExportDto : allRelevFileList){ for(OSSFile fileExportDto : allRelevFileList){
String oldPath = fileExportDto.getUrl(); String oldPath = fileExportDto.getUrl();
String newPath = fileNowPath + File.separator + fileExportDto.getFileName(); String newPath = fileNowPath + File.separator + fileExportDto.getFileName();
if (CosBootUtil.doesObjectExist(oldPath)){ if (CosBootUtil.doesObjectExist(oldPath)){
InputStream in = CosBootUtil.download(oldPath); try (InputStream in = CosBootUtil.download(oldPath);) {
copyFile1(in, newPath); copyFile1(in, newPath);
} catch (IOException e) {
e.printStackTrace();
log.error(e.getMessage(), e);
}
} }
} }
@@ -3326,6 +3339,8 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
bos.write(bytes, 0, len); bos.write(bytes, 0, len);
} }
// 关闭流 先开后关 后开先关 // 关闭流 先开后关 后开先关
// 先开后关,先开的输入流,再开的输出流,那么应该先关输出流,再关输入流
// 先关外层,再关内层。如BufferedInputStream包装了一个FileInputStream,那么先关BufferedInputStream,再关FileInputStream。
bos.close(); // 后开先关 bos.close(); // 后开先关
bis.close(); // 先开后关 bis.close(); // 先开后关
} }