现在的位置: 首页 > 综合 > 正文

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

2018年02月02日 ⁄ 综合 ⁄ 共 855字 ⁄ 字号 评论关闭
 

  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.   }  

抱歉!评论已关闭.