惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

云风的 BLOG
云风的 BLOG
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
IT之家
IT之家
Recent Announcements
Recent Announcements
B
Blog
D
Docker
V
V2EX
GbyAI
GbyAI
L
LangChain Blog
博客园 - Franky
U
Unit 42
T
The Blog of Author Tim Ferriss
A
About on SuperTechFans
博客园 - 【当耐特】
Google DeepMind News
Google DeepMind News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Vercel News
Vercel News
博客园_首页
D
DataBreaches.Net
人人都是产品经理
人人都是产品经理
Y
Y Combinator Blog
量子位
Blog — PlanetScale
Blog — PlanetScale
罗磊的独立博客

博客园 - hone

管理 java学习 服务器相关 总统和亿万富翁经典语录(转载) js学习笔记 最近学习计划 VC控制Excel 真乱(转自csdn) 沟通(网上搜集) 工作 无题 将文档发送到打印机(From MSN) 经典68个故事 Manually Invalidating All Stale Sessions 图形相关 在Oracle9i中计算时间差 六度分隔 经典故事 新年竟然第一篇?!
java的zip压缩(转自Jeet)
hone · 2005-03-22 · via 博客园 - hone

public static String compress(String s) throws IOException
        ByteArrayInputStream input 
= new ByteArrayInputStream(s.getBytes("UTF-8"));  
        ByteArrayOutputStream output 
= new ByteArrayOutputStream(1024); 
        GZIPOutputStream gzout 
= new GZIPOutputStream(output);  
 
        
byte[] buf=new byte[1024]; 
        
int number;  
 
         
        
while ((number = input.read(buf)) != -1){  
            gzout.write(buf,
0,number);  
        }
 
         
        gzout.close();  
        input.close(); 
         
        String result 
=new BASE64Encoder().encode(output.toByteArray()); 
         
        output.close(); 
         
        
return result; 
    }
 
     
    
public static String decompress(String data) throws IOException
        ByteArrayOutputStream output 
= new ByteArrayOutputStream(1024); 
        ByteArrayInputStream input 
= new ByteArrayInputStream(new BASE64Decoder().decodeBuffer(data));  
        GZIPInputStream gzinpt 
= new GZIPInputStream(input); 
        
byte[] buf = new byte[1024]; 
        
int number = 0
         
        
while((number = gzinpt.read(buf)) != -1)
            output.write(buf,
0,number); 
        }
 
          
        gzinpt.close(); 
        input.close(); 
         
        String result 
= new String(output.toString("UTF-8")); 
         
        output.close(); 
         
        
return result;  
         
    }