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);

  

你可能感兴趣的:(web压缩gzip响应)