• GzipOutputStream及GzipInputStream的用法


    GzipOutputStream及GzipInputStream的用法 - 搜索-gcgmh - ITeye技术网站

    Java代码  收藏代码
    1. ByteArrayOutputStream arrayOutputStream =new ByteArrayOutputStream();  
    2. GZIPOutputStream gop = new GZIPOutputStream(arrayOutputStream);  
    3. byte[] buffer = new byte[1024];  
    4. int len = 0;  
    5. while ((len = inputStream.read(buffer)) != -1) {  
    6.     gop.write(buffer, 0, len);  
    7. }  
    8. gop.finish(); //这个在写入arrayOutputStream时一定要有,否则不能完全写入  
    9. gop.close;  






    ----------------------------------------


    Java代码  收藏代码
    1. Header encoding = method.getResponseHeader("Content-Encoding");  
    2.         if (encoding != null) {  
    3.             if (encoding.getValue().equals("gzip")) {  
    4.                 bytes = GZipUtil.unzip(bytes);  
    5.             }  
    6.         }  
    7.   
    8.   
    9. public static byte[] unzip(InputStream in) throws IOException {  
    10.         // Open the compressed stream  
    11.         GZIPInputStream gin = new GZIPInputStream(in);  
    12.   
    13.         ByteArrayOutputStream out = new ByteArrayOutputStream();  
    14.   
    15.         // Transfer bytes from the compressed stream to the output stream  
    16.         byte[] buf = new byte[size];  
    17.         int len;  
    18.         while ((len = gin.read(buf)) > 0) {  
    19.             out.write(buf, 0, len);  
    20.         }  
    21.   
    22.         // Close the file and stream  
    23.         gin.close();  
    24.         out.close();  
    25.         return out.toByteArray();  
    26.     }  
  • 相关阅读:
    java web 开发入门
    程序优质网站
    为什么要放弃ssh框架
    JDK核心源码(2)
    Linux 格式化分区 报错Could not stat --- No such file or directory 和 partprobe 命令
    快照COW
    磁盘检测SMART工具
    python学习-3.一些常用模块用法
    python 学习2:生成器,迭代器,装饰器
    关于对SwfUpload的改造
  • 原文地址:https://www.cnblogs.com/lexus/p/2376687.html
Copyright © 2020-2023  润新知