java.util.zip.ZipEntry#getCrc ( )源码实例Demo

下面列出了java.util.zip.ZipEntry#getCrc ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: mycore   文件: MCRIView2Commands.java
private static void validateZipFile(ZipFile iviewImage) throws IOException {
    Enumeration<? extends ZipEntry> entries = iviewImage.entries();
    CRC32 crc = new CRC32();
    byte[] data = new byte[4096];
    int read;
    while (entries.hasMoreElements()) {
        ZipEntry entry = entries.nextElement();
        try (InputStream is = iviewImage.getInputStream(entry)) {
            while ((read = is.read(data, 0, data.length)) != -1) {
                crc.update(data, 0, read);
            }
        }
        if (entry.getCrc() != crc.getValue()) {
            throw new IOException("CRC32 does not match for entry: " + entry.getName());
        }
        crc.reset();
    }
}
 
源代码2 项目: buck   文件: GenAidlIntegrationTest.java
private String zipEntryDebugString(ZipEntry entryOne) {
  return "<ZE name="
      + entryOne.getName()
      + " crc="
      + entryOne.getCrc()
      + " comment="
      + entryOne.getComment()
      + " size="
      + entryOne.getSize()
      + " atime="
      + entryOne.getLastAccessTime()
      + " mtime="
      + entryOne.getLastModifiedTime()
      + " ctime="
      + entryOne.getCreationTime()
      + ">";
}
 
源代码3 项目: buck   文件: GenruleIntegrationTest.java
private String zipEntryDebugString(ZipEntry entryOne) {
  return "<ZE name="
      + entryOne.getName()
      + " crc="
      + entryOne.getCrc()
      + " comment="
      + entryOne.getComment()
      + " size="
      + entryOne.getSize()
      + " atime="
      + entryOne.getLastAccessTime()
      + " mtime="
      + entryOne.getLastModifiedTime()
      + " ctime="
      + entryOne.getCreationTime();
}
 
源代码4 项目: rxjava2-extras   文件: ZippedEntry.java
public ZippedEntry(ZipEntry e, InputStream is) {
    this.name = e.getName();
    this.time = e.getTime();
    // this.mtime = e.getLastModifiedTime();
    // this.atime = e.getLastAccessTime();
    // this.ctime = e.getCreationTime();
    this.crc = e.getCrc();
    this.size = e.getSize();
    this.csize = e.getCompressedSize();
    this.method = e.getMethod();
    this.extra = e.getExtra();
    this.comment = e.getComment();
    this.is = is;
}
 
@Override
public Boolean invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
    PrintStream logger = listener.getLogger();
    try (ZipFile zip = new ZipFile(f)) {
        logger.print("Checking ");
        logger.print(zip.size());
        logger.print(" zipped entries in ");
        logger.println(f.getAbsolutePath());

        Checksum checksum = new CRC32();
        byte[] buffer = new byte[4096];

        Enumeration<? extends ZipEntry> entries = zip.entries();
        while (entries.hasMoreElements()) {
            checksum.reset();

            ZipEntry entry = entries.nextElement();
            if (!entry.isDirectory()) {
                try (InputStream inputStream = zip.getInputStream(entry)) {
                    int length;
                    while ((length = IOUtils.read(inputStream, buffer)) > 0) {
                        checksum.update(buffer, 0, length);
                    }
                    if (checksum.getValue() != entry.getCrc()) {
                        listener.error("Checksum error in : " + f.getAbsolutePath() + ":" + entry.getName());
                        return false;
                    }
                }
            }
        }
        return true;
    } catch (ZipException e) {
        listener.error("Error validating zip file: " + e.getMessage());
        return false;
    } finally {
        logger.flush();
    }
}
 
源代码6 项目: rxjava-extras   文件: ZippedEntry.java
public ZippedEntry(ZipEntry e, InputStream is) {
    this.name = e.getName();
    this.time = e.getTime();
    // this.mtime = e.getLastModifiedTime();
    // this.atime = e.getLastAccessTime();
    // this.ctime = e.getCreationTime();
    this.crc = e.getCrc();
    this.size = e.getSize();
    this.csize = e.getCompressedSize();
    this.method = e.getMethod();
    this.extra = e.getExtra();
    this.comment = e.getComment();
    this.is = is;
}
 
源代码7 项目: pentaho-reporting   文件: ZipContentItem.java
public ZipContentItem( final ZipRepository repository,
                       final ZipContentLocation parent,
                       final ZipEntry zipEntry,
                       final byte[] bytes ) {
  if ( repository == null ) {
    throw new NullPointerException();
  }
  if ( zipEntry == null ) {
    throw new NullPointerException();
  }
  if ( bytes == null ) {
    throw new NullPointerException();
  }
  if ( parent == null ) {
    throw new NullPointerException();
  }

  this.parent = parent;
  this.repository = repository;
  this.comment = zipEntry.getComment();
  this.name = RepositoryUtilities.buildName( this, "/" );
  this.entryName = IOUtils.getInstance().getFileName( name );
  this.size = zipEntry.getSize();
  this.crc32 = zipEntry.getCrc();
  this.time = zipEntry.getTime();
  this.rawData = bytes;
  final int method = zipEntry.getMethod();
  if ( method == ZipEntry.STORED || method == ZipEntry.DEFLATED ) {
    this.method = new Integer( method );
  } else {
    this.method = new Integer( ZipEntry.DEFLATED );
  }
  this.compression = Deflater.DEFAULT_COMPRESSION;
}
 
源代码8 项目: buck   文件: ZipInspector.java
public long getCrc(String pathRelativeToRoot) throws IOException {
  try (ZipFile zipFile = new ZipFile(this.zipFile.toFile())) {
    ZipEntry entry = zipFile.getEntry(pathRelativeToRoot);
    long crc = entry.getCrc();
    Preconditions.checkState(crc != -1, "Error accessing crc for entry: %s", pathRelativeToRoot);
    return crc;
  }
}
 
源代码9 项目: Strata   文件: ZipUtils.java
private ZipKey(ZipEntry entry, Path resolvedPath) {
  this.resolvedPath = resolvedPath;
  this.crc = entry.getCrc();
  this.size = entry.getSize();
}