web压缩gzip响应

String data = "ggrgrgw4gergergregerge";
byte b[] = data.getBytes();
String gzipValue = request.getHeader("Accept-Encoding"); //是否支持gzip压缩
if(gzipValue.contains("gzip")){
    ByteArrayOutputStream baos = new ByteArrayOutputStream();//带缓存的字节输出流
    GZIPOutputStream gout = new GZIPOutputStream(baos);
    gout.write(b);
    b = baos.toByteArray();
    response.setHeader("Content-Encoding", "gzip");
    reponse.setContentLength(b.length);
}
    response.getOutputStream.write(b);

  

posted on 2015-12-02 20:58  颓废的悠然  阅读(326)  评论(0编辑  收藏  举报

导航