public void batchPropertyDownloadPptTemp(String accountingYear, String accountingPeriod, HttpServletResponse response) {
String targetPath = getPPTOutputName();
String excelTargetPath = getExcelOutputName();
File file1 = null;
File file2 = null;
try{
OutputStream outputStream = response.getOutputStream();
ZipArchiveOutputStream zous = new ZipArchiveOutputStream(outputStream);
zous.setUseZip64(Zip64Mode.AsNeeded);
log.info("输出路径:"+targetPath);
log.info("生产PPT的版本为:"+accountingYear+"-"+accountingPeriod);
pptService.processNewPPT(targetPath, accountingYear,accountingPeriod);
file1 = new File(targetPath);
InputStream inputStream1 = new FileInputStream(file1);
byte[] bytes = null;
ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int size;
while ((size = inputStream1.read(buffer)) != -1) {
baos1.write(buffer, 0, size);
}
bytes = baos1.toByteArray();
ArchiveEntry entry1 = new ZipArchiveEntry(accountingYear + "年" + accountingPeriod+ "月_" + getToday() + ".pptx");
zous.putArchiveEntry(entry1);
zous.write(bytes);
zous.closeArchiveEntry();
pptExcelDataService.getPptExcel(excelTargetPath, accountingYear,accountingPeriod);
file2 = new File(excelTargetPath);
InputStream inputStream2 = new FileInputStream(file2);
while ((size = inputStream2.read(buffer)) != -1) {
baos2.write(buffer, 0, size);
}
bytes = baos2.toByteArray();
ArchiveEntry entry2 = new ZipArchiveEntry(accountingYear + "年" + accountingPeriod+ "月_" + getToday() + ".xlsx");
zous.putArchiveEntry(entry2);
zous.write(bytes);
zous.closeArchiveEntry();
inputStream1.close();
inputStream2.close();
outputStream.flush();
outputStream.close();
baos1.close();
baos2.close();
zous.close();
} catch (Exception e) {
log.error("导出报表PPT异常:{[]}", e);
throw new BusinessException("导出报表PPT异常");
}finally {
if (file1 != null) {
if (file1.exists()) {
file1.delete();
}
}
if (file2 != null) {
if (file2.exists()) {
file2.delete();
}
}
}
}
IO流:java实现-压缩包zip
最新推荐文章于 2023-08-17 13:46:36 发布