当前位置: 首页>>代码示例>>Java>>正文


Java ZipArchiveEntry.getCrc方法代码示例

本文整理汇总了Java中org.apache.commons.compress.archivers.zip.ZipArchiveEntry.getCrc方法的典型用法代码示例。如果您正苦于以下问题:Java ZipArchiveEntry.getCrc方法的具体用法?Java ZipArchiveEntry.getCrc怎么用?Java ZipArchiveEntry.getCrc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.compress.archivers.zip.ZipArchiveEntry的用法示例。


在下文中一共展示了ZipArchiveEntry.getCrc方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findBestSource

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
/**
 * Find best source.
 *
 * @param source the source
 * @param target the target
 * @param targetEntry the target entry
 * @return the zip archive entry
 * @throws IOException Signals that an I/O exception has occurred.
 */
public ZipArchiveEntry findBestSource(ZipFile source, ZipFile target, ZipArchiveEntry targetEntry) throws IOException {
  ArrayList<ZipArchiveEntry> ret = new ArrayList<>();
  for (ZipArchiveEntry next : source.getEntries(targetEntry.getName())) {
    if (next.getCrc() == targetEntry.getCrc())
      return next;
    ret.add(next);
  }
  if (ret.size() == 0)
    return null;
  if (ret.size() == 1 || targetEntry.isDirectory())
    return ret.get(0);
  //More than one and no matching crc --- need to calculate xdeltas and pick the  shortest
  ZipArchiveEntry retEntry = null;
  for (ZipArchiveEntry sourceEntry : ret) {
    try (ByteArrayOutputStream outbytes = new ByteArrayOutputStream()) {
      Delta d = new Delta();
      DiffWriter diffWriter = new GDiffWriter(new DataOutputStream(outbytes));
      int sourceSize = (int) sourceEntry.getSize();
      byte[] sourceBytes = new byte[sourceSize];
      try (InputStream sourceStream = source.getInputStream(sourceEntry)) {
        for (int erg = sourceStream.read(sourceBytes); erg < sourceBytes.length; erg += sourceStream.read(sourceBytes, erg, sourceBytes.length - erg));
      }
      d.compute(sourceBytes, target.getInputStream(targetEntry), diffWriter);
      byte[] nextDiff = outbytes.toByteArray();
      if (calculatedDelta == null || calculatedDelta.length > nextDiff.length) {
        retEntry = sourceEntry;
        calculatedDelta = nextDiff;
      }
    }
  }
  return retEntry;
}
 
开发者ID:NitorCreations,项目名称:javaxdelta,代码行数:42,代码来源:JarDelta.java

示例2: getEntry

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
/**
 * Gets the entry.
 *
 * @param source the source
 * @param name the name
 * @param crc the crc
 * @return the entry
 */
private ZipArchiveEntry getEntry(ZipFile source, String name, long crc) {
  for (ZipArchiveEntry next : source.getEntries(name)) {
    if (next.getCrc() == crc)
      return next;
  }
  if (!JarDelta.zipFilesPattern.matcher(name).matches()) {
    return null;
  } else {
    return source.getEntry(name);
  }
}
 
开发者ID:NitorCreations,项目名称:javaxdelta,代码行数:20,代码来源:JarPatcher.java

示例3: closeEntry

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
/**
 * Close entry.
 *
 * @param output the output
 * @param outEntry the out entry
 * @param crc the crc
 * @throws IOException Signals that an I/O exception has occurred.
 */
private void closeEntry(ZipArchiveOutputStream output, ZipArchiveEntry outEntry, long crc) throws IOException {
  output.flush();
  output.closeArchiveEntry();
  if (outEntry.getCrc() != crc)
    throw new IOException("CRC mismatch for " + outEntry.getName());
}
 
开发者ID:NitorCreations,项目名称:javaxdelta,代码行数:15,代码来源:JarPatcher.java

示例4: equal

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
/**
 * Test if the content of two byte arrays is completly identical.
 *
 * @param sourceEntry the source entry
 * @param targetEntry the target entry
 * @return true if source and target contain the same bytes.
 */
public boolean equal(ZipArchiveEntry sourceEntry, ZipArchiveEntry targetEntry) {
  return (sourceEntry.getSize() == targetEntry.getSize()) && (sourceEntry.getCrc() == targetEntry.getCrc());
}
 
开发者ID:NitorCreations,项目名称:javaxdelta,代码行数:11,代码来源:JarDelta.java


注:本文中的org.apache.commons.compress.archivers.zip.ZipArchiveEntry.getCrc方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。