• Android 解压html压缩数据


    public static String unzipHTML(String s){
    		int endPos = s.indexOf("
    
    ");
    		if(endPos<10)
    			return s;
    		try{
    			String header = s.substring(0, endPos);
    			if(header.indexOf("Content-Encoding: gzip")!=-1){
    				String[] strs = s.split("
    
    ", 2);
    				
    				Log.d("com.she.jyass.c", strs[0] + "
    strs[1] len=" + strs[1].length());
    		
    				ByteArrayInputStream bis = new ByteArrayInputStream(strs[1].getBytes("Latin1"));
    				GZIPInputStream g = new GZIPInputStream(bis);
    		
    				BufferedReader br = new BufferedReader(new InputStreamReader(g));
    				StringBuffer sb = new StringBuffer();
    				char[] buffer = new char[10240];
    				int len;
    				while ( (len=br.read(buffer)) >0) {
    					sb.append(buffer, 0, len);
    				}
    				s = strs[0] + "
    
    " + sb.toString();			
    			}
    		}catch(Exception e){
    			commonUtils.printError(e, "unzipHTML");
    		}
    		return s;
    	}

    使用方法:

    String s = new String(rtn.data, "Latin1");
    
    s = commonUtils.unzipHTML(s);


    注意,即使你的网页是utf-8的,也要用Latin1,否则出来的是乱码

  • 相关阅读:
    MARTIN FOWLER谈敏捷开发
    精益创业
    DEVOPS基础
    测试驱动开发
    持续集成(CONTINUOUS INTEGRATION)
    极限编程
    回归测试
    敏捷开发十二原则
    敏捷开发宣言
    敏捷开发简史
  • 原文地址:https://www.cnblogs.com/lein317/p/5067535.html
Copyright © 2020-2023  润新知