update 优化 downloadCode 两个重载 ZipOutputStream 异常的处理方式。

This commit is contained in:
CodeLancet 2026-10-09 21:40:13 +08:00
parent 03e8f097b2
commit e1bdb03d69

View File

@ -340,11 +340,10 @@ public class GenTableServiceImpl implements IGenTableService {
@Override @Override
public byte[] downloadCode(Long tableId) { public byte[] downloadCode(Long tableId) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(outputStream); try(ZipOutputStream zip = new ZipOutputStream(outputStream)) {
try {
writeCodeToZip(tableId, zip); writeCodeToZip(tableId, zip);
} finally { } catch (IOException e) {
IoUtil.close(zip); log.error("渲染模板失败,Zip输出流IO异常。", e);
} }
return outputStream.toByteArray(); return outputStream.toByteArray();
} }
@ -410,13 +409,12 @@ public class GenTableServiceImpl implements IGenTableService {
@Override @Override
public byte[] downloadCode(String[] tableIds) { public byte[] downloadCode(String[] tableIds) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(outputStream); try(ZipOutputStream zip = new ZipOutputStream(outputStream)) {
try {
for (String tableId : tableIds) { for (String tableId : tableIds) {
writeCodeToZip(Long.parseLong(tableId), zip); writeCodeToZip(Long.parseLong(tableId), zip);
} }
} finally { } catch (IOException e) {
IoUtil.close(zip); log.error("渲染模板失败,Zip输出流IO异常。", e);
} }
return outputStream.toByteArray(); return outputStream.toByteArray();
} }