refactor(接口测试): 优化执行过程附件下载压缩方法

This commit is contained in:
fit2-zhao 2022-12-22 15:36:39 +08:00 committed by fit2-zhao
parent 0765d0086b
commit ee5442b44d
1 changed files with 10 additions and 10 deletions

View File

@ -288,21 +288,21 @@ public class ApiJMeterFileService {
return listBytesToZip(files); return listBytesToZip(files);
} }
private byte[] listBytesToZip(Map<String, byte[]> mapReport) { private byte[] listBytesToZip(Map<String, byte[]> content) {
try { try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ZipOutputStream zos = new ZipOutputStream(byteArrayOutputStream)) {
ZipOutputStream zos = new ZipOutputStream(baos); for (String key : content.keySet()) {
for (Map.Entry<String, byte[]> report : mapReport.entrySet()) { ZipEntry entry = new ZipEntry(key);
ZipEntry entry = new ZipEntry(report.getKey()); entry.setSize(content.get(key).length);
entry.setSize(report.getValue().length);
zos.putNextEntry(entry); zos.putNextEntry(entry);
zos.write(report.getValue()); zos.write(content.get(key));
} }
zos.closeEntry(); zos.closeEntry();
zos.close(); zos.close();
return baos.toByteArray(); return byteArrayOutputStream.toByteArray();
} catch (Exception e) { } catch (Exception e) {
return null; LogUtil.error(e);
return new byte[0];
} }
} }