public void setTime(ZipEntry newInstance, ZipEntry oldInstance) { long time = oldInstance.getTime(); if (time != -1) { newInstance.setTime(time); } }
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); } } } }
/** * 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(); }
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(); }
/** * 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(); }
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; } }
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(); }
e.setTime(f.lastModified()); jos.putNextEntry(e); FileInputStream fis = new FileInputStream(f);
/** * 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(); }
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); }
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; }
/** * 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); }
zipEntry.setTime(file.lastModified());
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; }
/** * 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; }
zipEntry.setTime(file.lastModified());
/** * 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); }
/** * 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; }