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