java.util.zip.ZipEntry.setCrc()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(173)

本文整理了Java中java.util.zip.ZipEntry.setCrc()方法的一些代码示例,展示了ZipEntry.setCrc()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipEntry.setCrc()方法的具体详情如下:
包路径:java.util.zip.ZipEntry
类名称:ZipEntry
方法名:setCrc

ZipEntry.setCrc介绍

[英]Sets the checksum for this ZipEntry.
[中]设置此ZipEntry的校验和。

代码示例

代码示例来源:origin: redisson/redisson

public static void addFolderToZip(ZipOutputStream zos, String path, String comment) throws IOException {
  while (path.length() != 0 && path.charAt(0) == '/') {
    path = path.substring(1);
  }
  // add folder record
  if (!StringUtil.endsWithChar(path, '/')) {
    path += '/';
  }
  ZipEntry zipEntry = new ZipEntry(path);
  zipEntry.setTime(System.currentTimeMillis());
  if (comment != null) {
    zipEntry.setComment(comment);
  }
  zipEntry.setSize(0);
  zipEntry.setCrc(0);
  zos.putNextEntry(zipEntry);
  zos.closeEntry();
}

代码示例来源:origin: iBotPeaches/Apktool

BufferedInputStream unknownFile = new BufferedInputStream(new FileInputStream(file));
  CRC32 crc = BrutIO.calculateCrc(unknownFile);
  zipEntry.setCrc(crc.getValue());
  unknownFile.close();
} else {

代码示例来源:origin: iBotPeaches/Apktool

private void copyUnknownFiles(File appDir, ZipOutputStream outputFile, Map<String, String> files)
    throws BrutException, IOException {
  File unknownFileDir = new File(appDir, UNK_DIRNAME);
  // loop through unknown files
  for (Map.Entry<String,String> unknownFileInfo : files.entrySet()) {
    File inputFile = new File(unknownFileDir, BrutIO.sanitizeUnknownFile(unknownFileDir, unknownFileInfo.getKey()));
    if (inputFile.isDirectory()) {
      continue;
    }
    ZipEntry newEntry = new ZipEntry(unknownFileInfo.getKey());
    int method = Integer.parseInt(unknownFileInfo.getValue());
    LOGGER.fine(String.format("Copying unknown file %s with method %d", unknownFileInfo.getKey(), method));
    if (method == ZipEntry.STORED) {
      newEntry.setMethod(ZipEntry.STORED);
      newEntry.setSize(inputFile.length());
      newEntry.setCompressedSize(-1);
      BufferedInputStream unknownFile = new BufferedInputStream(new FileInputStream(inputFile));
      CRC32 crc = BrutIO.calculateCrc(unknownFile);
      newEntry.setCrc(crc.getValue());
    } else {
      newEntry.setMethod(ZipEntry.DEFLATED);
    }
    outputFile.putNextEntry(newEntry);
    BrutIO.copy(inputFile, outputFile);
    outputFile.closeEntry();
  }
}

代码示例来源:origin: oblac/jodd

public static void addFolderToZip(final ZipOutputStream zos, String path, final String comment) throws IOException {
  while (path.length() != 0 && path.charAt(0) == '/') {
    path = path.substring(1);
  }
  // add folder record
  if (!StringUtil.endsWithChar(path, '/')) {
    path += '/';
  }
  ZipEntry zipEntry = new ZipEntry(path);
  zipEntry.setTime(System.currentTimeMillis());
  if (comment != null) {
    zipEntry.setComment(comment);
  }
  zipEntry.setSize(0);
  zipEntry.setCrc(0);
  zos.putNextEntry(zipEntry);
  zos.closeEntry();
}

代码示例来源:origin: pxb1988/dex2jar

@Override
public void closeEntry() throws IOException {
  ZipEntry delayedEntry = this.delayedEntry;
  if (delayedEntry != null) {
    AccessBufByteArrayOutputStream delayedOutputStream = this.delayedOutputStream;
    byte[] buf = delayedOutputStream.getBuf();
    int size = delayedOutputStream.size();
    delayedEntry.setSize(size);
    delayedEntry.setCompressedSize(size);
    crc.reset();
    crc.update(buf, 0, size);
    delayedEntry.setCrc(crc.getValue());
    super.putNextEntry(delayedEntry);
    super.write(buf, 0, size);
    this.delayedEntry = null;
    delayedOutputStream.reset();
  }
  super.closeEntry();
}

代码示例来源:origin: org.apache.ant/ant

private void addFile(ZipOutputStream output, File file, String prefix,
           boolean compress) throws IOException {
  //Make sure file exists
  if (!file.exists()) {
    return;
  }
  ZipEntry entry = new ZipEntry(getEntryName(file, prefix));
  entry.setTime(file.lastModified());
  entry.setSize(file.length());
  if (!compress) {
    entry.setCrc(calcChecksum(file));
  }
  addToOutputStream(output, Files.newInputStream(file.toPath()), entry);
}

代码示例来源:origin: guoguibing/librec

entry.setCompressedSize(file.length());
entry.setSize(file.length());
entry.setCrc(crc.getValue());
zos.putNextEntry(entry);
while ((bytesRead = bis.read(buffer)) != -1) {

代码示例来源:origin: iBotPeaches/Apktool

entry = new ZipEntry("resources.arsc");
entry.setSize(data.length);
entry.setCrc(crc.getValue());
out.putNextEntry(entry);
out.write(data);
  entry.setSize(manifest.length);
  entry.setCompressedSize(-1);
  entry.setCrc(manifestCrc.getValue());
  out.putNextEntry(entry);
  out.write(manifest);

代码示例来源:origin: google/j2objc

CRC32 crc = new CRC32();
crc.update(bytes);
outEntry.setCrc( crc.getValue() );
outEntry.setCompressedSize(bytes.length);

代码示例来源:origin: redisson/redisson

zipEntry.setCrc(0);

代码示例来源:origin: Sable/soot

private void copyAllButClassesDexAndSigFiles(ZipFile source, ZipOutputStream destination) throws IOException {
 Enumeration<? extends ZipEntry> sourceEntries = source.entries();
 while (sourceEntries.hasMoreElements()) {
  ZipEntry sourceEntry = sourceEntries.nextElement();
  String sourceEntryName = sourceEntry.getName();
  if (sourceEntryName.endsWith(".dex") || isSignatureFile(sourceEntryName)) {
   continue;
  }
  // separate ZipEntry avoids compression problems due to encodings
  ZipEntry destinationEntry = new ZipEntry(sourceEntryName);
  // use the same compression method as the original (certain files
  // are stored, not compressed)
  destinationEntry.setMethod(sourceEntry.getMethod());
  // copy other necessary fields for STORE method
  destinationEntry.setSize(sourceEntry.getSize());
  destinationEntry.setCrc(sourceEntry.getCrc());
  // finally craft new entry
  destination.putNextEntry(destinationEntry);
  InputStream zipEntryInput = source.getInputStream(sourceEntry);
  byte[] buffer = new byte[2048];
  int bytesRead = zipEntryInput.read(buffer);
  while (bytesRead > 0) {
   destination.write(buffer, 0, bytesRead);
   bytesRead = zipEntryInput.read(buffer);
  }
  zipEntryInput.close();
 }
}

代码示例来源:origin: zeroturnaround/zt-zip

public ZipEntry getEntry() {
 ZipEntry entry = new ZipEntry(path);
 if (bytes != null) {
  entry.setSize(bytes.length);
 }
 if(compressionMethod != -1) {
  entry.setMethod(compressionMethod);
 }
 if(crc != -1L) {
  entry.setCrc(crc);
 }
 entry.setTime(time);
 return entry;
}

代码示例来源:origin: org.easymock/easymock

CRC32 crc = new CRC32();
crc.update(bytes);
outEntry.setCrc( crc.getValue() );
outEntry.setCompressedSize(bytes.length);

代码示例来源:origin: cglib/cglib

CRC32 crc = new CRC32();
crc.update(bytes);
outEntry.setCrc( crc.getValue() );
outEntry.setCompressedSize(bytes.length);

代码示例来源:origin: oblac/jodd

zipEntry.setCrc(0);

代码示例来源:origin: cglib/cglib

CRC32 crc = new CRC32();
crc.update(bytes);
outEntry.setCrc( crc.getValue() );
outEntry.setCompressedSize(bytes.length);

代码示例来源:origin: org.apache.ant/ant

outputEntry.setCrc(inputEntry.getCrc());
outputEntry.setSize(inputEntry.getSize());

代码示例来源:origin: zeroturnaround/zt-zip

/**
 * Copy entry with another name.
 *
 * @param original - zipEntry to copy
 * @param newName - new entry name, optional, if null, ogirinal's entry
 * @return copy of the original entry, but with the given name
 */
static ZipEntry copy(ZipEntry original, String newName) {
 ZipEntry copy = new ZipEntry(newName == null ? original.getName() : newName);
 if (original.getCrc() != -1) {
  copy.setCrc(original.getCrc());
 }
 if (original.getMethod() != -1) {
  copy.setMethod(original.getMethod());
 }
 if (original.getSize() >= 0) {
  copy.setSize(original.getSize());
 }
 if (original.getExtra() != null) {
  copy.setExtra(original.getExtra());
 }
 copy.setComment(original.getComment());
 copy.setTime(original.getTime());
 return copy;
}

代码示例来源:origin: robovm/robovm

currentEntry.setMethod(ceCompressionMethod);
if (ceSize != -1) {
  currentEntry.setCrc(ceCrc);
  currentEntry.setSize(ceSize);
  currentEntry.setCompressedSize(ceCompressedSize);

代码示例来源:origin: apache/tika

private static void zipStoreBuffer(ZipArchiveOutputStream zip, String name, byte[] dataBuffer) throws IOException {
  ZipEntry zipEntry = new ZipEntry(name != null ? name : UUID.randomUUID().toString());
  zipEntry.setMethod(ZipOutputStream.STORED);
  zipEntry.setSize(dataBuffer.length);
  CRC32 crc32 = new CRC32();
  crc32.update(dataBuffer);
  zipEntry.setCrc(crc32.getValue());
  try {
    zip.putArchiveEntry(new ZipArchiveEntry(zipEntry));
  } catch (ZipException ex) {
    if (name != null) {
      zipStoreBuffer(zip, "x-" + name, dataBuffer);
      return;
    }
  }
  zip.write(dataBuffer);
  zip.closeArchiveEntry();
}

相关文章