处理被Gzip的压缩过的数据

2017/06/23 19:15
阅读数 15
String contentEncoding = con.getContentEncoding();
    InputStream in = con.getInputStream();


    if ("gzip".equalsIgnoreCase(contentEncoding))
      in = new GZIPInputStream(in);
    else "deflate".equalsIgnoreCase(contentEncoding);


    StringBuilder sb = new StringBuilder("");
    BufferedReader reader = new BufferedReader(new InputStreamReader(in, BSUtil.isNullOrEmpty(request.getResponseEncoding()) ? "UTF-8" : request.getResponseEncoding()));
    String line = "";
    while ((line = reader.readLine()) != null) {
      sb.append(line).append("\r\n");
    }
    reader.close();


    con.disconnect();
    response.setPage(sb.toString());
    response.setCode(con.getResponseCode());
展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部