jar完整性测试的Java代码收藏

本文介绍了一种使用CRC校验进行jar文件完整性的Java实现方法,并列举了可能出现的一些异常情况及其处理方式。
 
  1. /** 
  2.  * jar完整性测试/检测的Java代码(CRC检测)<br> 
  3.  * 一些常见的异常,也就是类似CRC异常 <br> 
  4.  * Unexpected end of ZLIB input stream<br> 
  5.  * oversubscribed dynamic bit lengths tree 
  6.  *  
  7.  * @param fileName 
  8.  * @return 
  9.  */  
  10. public static boolean checkJarFile(File fileName) {  
  11.   try {  
  12.     JarFile jf = new JarFile(fileName);  
  13.     for (Enumeration e = jf.entries(); e.hasMoreElements();) {  
  14.       JarEntry je = (JarEntry) e.nextElement();  
  15.       String outFileName = je.getName();  
  16.       if (outFileName.endsWith("/") || outFileName.endsWith("//") || outFileName.endsWith(File.separator)) {} else {  
  17.         InputStream in = jf.getInputStream(je);  
  18.         byte[] buffer = new byte[2048];  
  19.         while (in.read(buffer) > 0) {  
  20.           ;  
  21.         }  
  22.         in.close();  
  23.       }  
  24.     }  
  25.     return true;  
  26.   } catch (Exception ex) {  
  27.     ex.printStackTrace();  
  28.     return false;  
  29.   }  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值