关于gzip服务端读取方法
来源:互联网 发布:淘宝网电风扇 编辑:程序博客网 时间:2024/04/29 10:12
public String getParametersJsonString(HttpServletRequest request) {
byte[] bt = null;
String json = null;
InputStream in = null;
ByteArrayInputStream bin = null;
GZIPInputStream ginzip = null;
ByteArrayOutputStream out = null;
try {
in = request.getInputStream();
bt = IOUtils.toByteArray(in);
json = IOUtils.toString(bt, DEFAULT_CHARSET);
if (!StringUtils.startsWith(json, "{")) {
//如果不是json格式,则进行解压
bin = new ByteArrayInputStream(bt);
ginzip = new GZIPInputStream(bin);
out = new ByteArrayOutputStream();
IOUtils.copy(ginzip, out);
json = IOUtils.toString(out.toByteArray(), DEFAULT_CHARSET);
if (StringUtils.isBlank(json)) {
LogUtil.error("gzip解压请求数据为空.");
}
}
} catch (IOException e) {
ExceptionUtil.caught(e, e.getMessage());
} finally {
if (in!=null) {
try {
in.close();
} catch (IOException e) {
in = null;
}
}
if (bin!=null) {
try {
bin.close();
} catch (IOException e) {
bin = null;
}
}
if (ginzip!=null) {
try {
ginzip.close();
} catch (IOException e) {
ginzip = null;
}
}
if (out!=null) {
try {
out.close();
} catch (IOException e) {
out = null;
}
}
}
return json;
}
byte[] bt = null;
String json = null;
InputStream in = null;
ByteArrayInputStream bin = null;
GZIPInputStream ginzip = null;
ByteArrayOutputStream out = null;
try {
in = request.getInputStream();
bt = IOUtils.toByteArray(in);
json = IOUtils.toString(bt, DEFAULT_CHARSET);
if (!StringUtils.startsWith(json, "{")) {
//如果不是json格式,则进行解压
bin = new ByteArrayInputStream(bt);
ginzip = new GZIPInputStream(bin);
out = new ByteArrayOutputStream();
IOUtils.copy(ginzip, out);
json = IOUtils.toString(out.toByteArray(), DEFAULT_CHARSET);
if (StringUtils.isBlank(json)) {
LogUtil.error("gzip解压请求数据为空.");
}
}
} catch (IOException e) {
ExceptionUtil.caught(e, e.getMessage());
} finally {
if (in!=null) {
try {
in.close();
} catch (IOException e) {
in = null;
}
}
if (bin!=null) {
try {
bin.close();
} catch (IOException e) {
bin = null;
}
}
if (ginzip!=null) {
try {
ginzip.close();
} catch (IOException e) {
ginzip = null;
}
}
if (out!=null) {
try {
out.close();
} catch (IOException e) {
out = null;
}
}
}
return json;
}
0 0
- 关于gzip服务端读取方法
- 关于JavaScript的gzip静态压缩方法
- python读取gzip格式及普通格式网页的方法
- ASP.NET服务端GZIP压缩
- ASP.NET服务端GZIP压缩
- Java读取GZIP
- 通过JScript 来读取服务端文件的方法
- 关于cmwap和gzip
- IIS GZIP 压缩方法
- Tomcat开启gzip方法
- xampp开启gzip方法
- 关于搭建ftp服务端的流程方法介绍
- 关于HTTP GZIP解压问题
- 关于http的gzip解压
- 关于文件路径读取的几个方法
- 关于python读取大文件的方法
- 关于Java读取access的方法
- 关于JUnit无法读取到方法总结
- codeforces 484a Bits
- 通过js去对表格的列,根据其内容进行排序(升序或者降序)
- JavaScript中的prototype使用说明
- git根据commit生成patch And Git的Patch功能
- 总结:调用startActivityForResult,onActivityResult无响应的问题
- 关于gzip服务端读取方法
- struts+spring+hibernate整合出现的问题解决方法
- HDU 1.2.4 decimal system
- [HDU 1078]FatMouse and Cheese(记忆化DFS)
- 搭建golang的beego注意事项
- Docker的官网在线--中文教程
- war包无法正常工作 JasperException, jstl.jar
- apache tomcat 整合
- 雷霆湖人饱受伤病可凑残蓝队 1