/**
* 条件查询配置项列表,只返回配置项id,编号,名称
* @return
*/
public void show() throws IOException {
HttpServletResponse response = ServletActionContext.getResponse();
// 取得用户的组织机构
String deptId = super.getLoginDeptId();
PageDto pageDto = configService.getConfigList(cid,this.getPageInfo(),
sysCode,projectConfig, prjId,enable,deptId);
response.setHeader("Content-Encoding","gzip");
response.setHeader("Content-Type","application/json;charset=UTF-8");
ServletOutputStream outputStream = response.getOutputStream();
PageAction pageAction = new PageAction();
pageAction.setStatus(0);
pageAction.setTotal(pageDto.getTotalRecord());
pageAction.setDataList(pageDto.getRecordList());
outputStream.write(compress(JSON.toJSONString(pageAction)));
}
private byte[] compress(String primStr) {
if (primStr == null || primStr.length() == 0) {
return null;
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
GZIPOutputStream gzip = null;
try {
byte[] bytes = primStr.getBytes(StandardCharsets.UTF_8);
LOGGER.info("----压缩前数据大小:{}",bytes.length);
System.out.println("----压缩前数据大小:"+bytes.length);
gzip = new GZIPOutputStream(out);
gzip.write(bytes);
LOGGER.info("----压缩前数据大小:{}",out.size());
System.out.println("----压缩前数据大小:{}"+out.size());
System.out.println("压缩比:"+bytes.length/out.size());
} catch (IOException e) {
e.printStackTrace();
} finally {
if (gzip != null) {
try {
gzip.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return out.toByteArray();
}
gzip压缩返回体
最新推荐文章于 2023-04-19 00:56:35 发布