Java Code Examples for java.util.zip.ZipEntry#getCrc()

The following examples show how to use java.util.zip.ZipEntry#getCrc() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MCRIView2Commands.java    From mycore with GNU General Public License v3.0 6 votes vote down vote up
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();
    }
}
 
Example 2
Source File: GenAidlIntegrationTest.java    From buck with Apache License 2.0 6 votes vote down vote up
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()
      + ">";
}
 
Example 3
Source File: GenruleIntegrationTest.java    From buck with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example 4
Source File: ZippedEntry.java    From rxjava2-extras with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 5
Source File: UnZipStepExecution.java    From pipeline-utility-steps-plugin with MIT License 5 votes vote down vote up
@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();
    }
}
 
Example 6
Source File: ZippedEntry.java    From rxjava-extras with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 7
Source File: ZipContentItem.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
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;
}
 
Example 8
Source File: ZipInspector.java    From buck with Apache License 2.0 5 votes vote down vote up
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;
  }
}
 
Example 9
Source File: ZipUtils.java    From Strata with Apache License 2.0 4 votes vote down vote up
private ZipKey(ZipEntry entry, Path resolvedPath) {
  this.resolvedPath = resolvedPath;
  this.crc = entry.getCrc();
  this.size = entry.getSize();
}