zoukankan      html  css  js  c++  java
  • 网站压缩数据 GZIP

     1 //1、被压缩数据
     2             String str="Hello 你好Hello 你好Hello 你好Hello 你好Hello 你好Hello 你好Hello 你好Hello 你好Hello 你好Hello 你好Hello 你好Hello 你好Hello 你好Hello 你好Hello 你好Hello 你好Hello 你好Hello 你好Hello 你好Hello 你好Hello 你好Hello 你好Hello 你好Hello 你好Hello 你好Hello 你好";
     3             //2、获得被压缩数据的字节码
     4             byte[] bytes=str.getBytes("utf-8");
     5             //3、声明一个输出流容器
     6             ByteArrayOutputStream byteout=new ByteArrayOutputStream();
     7             //4、声明压缩工具流,并设置压缩目的
     8             GZIPOutputStream zip=new GZIPOutputStream(byteout);
     9             //5、写入数据
    10             zip.write(bytes);
    11             //6、关闭工具(如果不关闭,不能写入)
    12             zip.close();
    13             
    14             System.out.println("压缩前:"+str.length());
    15             //7、压缩以后的字节码
    16             byte[] descbyte= byteout.toByteArray();
    17             System.out.println("压缩后:"+descbyte.length);
    18             //8、设置编码
    19             response.setContentType("text/html;charset=utf-8");
    20             //9、通知浏览器这是压缩,要求解码显示(必须)
    21             response.setHeader("Content-encoding", "gzip");
    22             //10、通知浏览器压缩字节长度(非必须)
    23             response.setContentLength(descbyte.length);
    24             //11、必须使用字节流输出信息
    25             OutputStream out=response.getOutputStream();
    26             //12、写入
    27             out.write(descbyte);
  • 相关阅读:
    .Net并行编程
    ShopEx4.8.5.55328破解版
    PLinq
    C# 4.0 Parallel
    WCF、Web API、WCF REST、Web Service
    WCF 采用net.tcp协议
    MVC 过滤器3
    go orcale
    获取合并单元格中值的一个方法POI
    发起、维持和发展以利润为导向的企业的有目的性的行为(转)
  • 原文地址:https://www.cnblogs.com/liuwt365/p/4127105.html
Copyright © 2011-2022 走看看