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

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

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

ZipEntry.setTime介绍

[英]Sets the modification time of this ZipEntry.
[中]设置此ZipEntry的修改时间。

代码示例

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

public void setTime(ZipEntry newInstance, ZipEntry oldInstance) {
 long time = oldInstance.getTime();
 if (time != -1) {
  newInstance.setTime(time);
 }
}

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

void addToZip(ZipPath path, File srcFile, ZipOutputStream zip, boolean excludeRootDir) throws IOException {
  if (srcFile.isDirectory()) {
    addFolderToZip(path, srcFile, zip, excludeRootDir);
  } else {
    byte[] buff = new byte[4096];
    try (BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(srcFile))) {
      ZipEntry zipEntry = path.with(srcFile).asZipEntry();
      zipEntry.setTime(srcFile.lastModified());
      zip.putNextEntry(zipEntry);
      int len;
      while ((len = inputStream.read(buff)) > 0) {
        zip.write(buff, 0, len);
      }
    }
  }
}

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

/**
 * Transforms the input stream entry, writes that to output stream, closes entry in the output stream.
 *
 * @param in input stream of the entry contents
 * @param zipEntry zip entry metadata
 * @param out output stream to write transformed entry (if necessary)
 *
 * @throws IOException if anything goes wrong
 */
public void transform(InputStream in, ZipEntry zipEntry, ZipOutputStream out) throws IOException {
 ZipEntry entry = new ZipEntry(zipEntry.getName());
 entry.setTime(System.currentTimeMillis());
 out.putNextEntry(entry);
 transform(zipEntry, in, out);
 out.closeEntry();
}

代码示例来源: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: redisson/redisson

/**
 * Adds byte content into the zip as a file.
 */
public static void addToZip(ZipOutputStream zos, byte[] content, String path, String comment) throws IOException {
  while (path.length() != 0 && path.charAt(0) == '/') {
    path = path.substring(1);
  }
  if (StringUtil.endsWithChar(path, '/')) {
    path = path.substring(0, path.length() - 1);
  }
  ZipEntry zipEntry = new ZipEntry(path);
  zipEntry.setTime(System.currentTimeMillis());
  if (comment != null) {
    zipEntry.setComment(comment);
  }
  zos.putNextEntry(zipEntry);
  InputStream is = new ByteArrayInputStream(content);
  try {
    StreamUtil.copy(is, zos);
  } finally {
    StreamUtil.close(is);
  }
  zos.closeEntry();
}

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

private @CheckForNull
OutputStream getOutputStream(String fullName, long lastModifiedTime) throws IOException {
  if (kind == SrcKind.DIR) {
    dstFile = new File(src, fullName);
    if (dstFile.exists()) {
      System.out.println(dstFile + " already exists");
      return null;
    }
    File parent = dstFile.getParentFile();
    OutputStream out = null;
    if (!parent.mkdirs() && !parent.isDirectory()) {
      String path = parent.getPath();
      if (couldNotCreate.add(path)) {
        System.out.println("Can't create directory for " + path);
      }
      return null;
    }
    return new FileOutputStream(dstFile);
  } else {
    ZipEntry e = new ZipEntry(fullName);
    e.setTime(lastModifiedTime);
    zOut.putNextEntry(e);
    return zOut;
  }
}

代码示例来源: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: stackoverflow.com

name += "/";
  JarEntry entry = new JarEntry(name);
  entry.setTime(source.lastModified());
  target.putNextEntry(entry);
  target.closeEntry();
entry.setTime(source.lastModified());
target.putNextEntry(entry);
in = new BufferedInputStream(new FileInputStream(source));

代码示例来源:origin: bytedeco/javacpp

e.setTime(f.lastModified());
jos.putNextEntry(e);
FileInputStream fis = new FileInputStream(f);

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

/**
 * Adds byte content into the zip as a file.
 */
public static void addToZip(final ZipOutputStream zos, final byte[] content, String path, final String comment) throws IOException {
  while (path.length() != 0 && path.charAt(0) == '/') {
    path = path.substring(1);
  }
  if (StringUtil.endsWithChar(path, '/')) {
    path = path.substring(0, path.length() - 1);
  }
  ZipEntry zipEntry = new ZipEntry(path);
  zipEntry.setTime(System.currentTimeMillis());
  if (comment != null) {
    zipEntry.setComment(comment);
  }
  zos.putNextEntry(zipEntry);
  InputStream is = new ByteArrayInputStream(content);
  try {
    StreamUtil.copy(is, zos);
  } finally {
    StreamUtil.close(is);
  }
  zos.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: spotbugs/spotbugs

public ZipEntry newZipEntry(ZipEntry ze) {
  ZipEntry ze2 = new ZipEntry(ze.getName());
  ze2.setComment(ze.getComment());
  ze2.setTime(ze.getTime());
  ze2.setExtra(ze.getExtra());
  return ze2;
}

代码示例来源:origin: uber/NullAway

/**
 * Write model jar file with nullability model at DEFAULT_ASTUBX_LOCATION
 *
 * @param outPath Path of output model jar file.
 */
private static void writeModelJAR(String outPath) throws IOException {
 Preconditions.checkArgument(
   outPath.endsWith(MODEL_JAR_SUFFIX), "invalid model file path! " + outPath);
 ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(outPath));
 if (!map_result.isEmpty()) {
  ZipEntry entry = new ZipEntry(DEFAULT_ASTUBX_LOCATION);
  // Set the modification/creation time to 0 to ensure that this jars always have the same
  // checksum
  entry.setTime(0);
  entry.setCreationTime(FileTime.fromMillis(0));
  zos.putNextEntry(entry);
  writeModel(new DataOutputStream(zos));
  zos.closeEntry();
 }
 zos.close();
 LOG(VERBOSE, "Info", "wrote model to: " + outPath);
}

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

zipEntry.setTime(file.lastModified());

代码示例来源: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: zeroturnaround/zt-zip

/**
 * Create new Zip entry and fill it with associated with file meta-info
 * 
 * @param name Zip entry name
 * @param file source File
 * @return newly created Zip entry
 */
static ZipEntry fromFile(String name, File file) {
 ZipEntry zipEntry = new ZipEntry(name);
 if (!file.isDirectory()) {
  zipEntry.setSize(file.length());
 }
 zipEntry.setTime(file.lastModified());
 ZTFilePermissions permissions = ZTFilePermissionsUtil.getDefaultStategy().getPermissions(file);
 if (permissions != null) {
  ZipEntryUtil.setZTFilePermissions(zipEntry, permissions);
 }
 return zipEntry;
}

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

zipEntry.setTime(file.lastModified());

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

/**
 * Copies a given ZIP entry to a ZIP file. If this.preserveTimestamps is true, original timestamp
 * is carried over, otherwise uses current time.
 *
 * @param originalEntry
 *          a ZIP entry from existing ZIP file.
 * @param in
 *          contents of the ZIP entry.
 * @param out
 *          target ZIP stream.
 */
static void copyEntry(ZipEntry originalEntry, InputStream in, ZipOutputStream out, boolean preserveTimestamps) throws IOException {
 ZipEntry copy = copy(originalEntry);
 if (preserveTimestamps) {
  TimestampStrategyFactory.getInstance().setTime(copy, originalEntry);
 }
 else {
  copy.setTime(System.currentTimeMillis());
 }
 
 addEntry(copy, new BufferedInputStream(in), out);
}

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

outputEntry.setTime(inputEntry.getTime());
outputEntry.setExtra(inputEntry.getExtra());
outputEntry.setComment(inputEntry.getComment());
outputEntry.setTime(inputEntry.getTime());
if (compression) {
  outputEntry.setMethod(ZipEntry.DEFLATED);

代码示例来源: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;
}

相关文章