List of usage examples for java.util.zip ZipEntry getTime
public long getTime()
From source file:org.eclipse.smila.utils.compression.CompressionHelper.java
/** * /** Unzip.//from w w w. j a v a 2 s . c om * * @param dest * the dest * @param inputStream * the input stream * * @throws IOException * Signals that an I/O exception has occurred. */ public static void unzip(final File dest, final InputStream inputStream) throws IOException { ZipInputStream zis = null; FileOutputStream fileOutputStream = null; BufferedOutputStream bufferedOutputStream = null; try { zis = new ZipInputStream(inputStream); ZipEntry entry; while ((entry = zis.getNextEntry()) != null) { if (entry.isDirectory()) { new File(dest, entry.getName()).mkdir(); continue; } final File destFile = new File(dest, entry.getName()); if (!destFile.getParentFile().exists()) { destFile.getParentFile().mkdirs(); } try { fileOutputStream = new FileOutputStream(destFile); bufferedOutputStream = new BufferedOutputStream(fileOutputStream); IOUtils.copy(zis, bufferedOutputStream); } finally { IOUtils.closeQuietly(fileOutputStream); IOUtils.closeQuietly(bufferedOutputStream); } destFile.setLastModified(entry.getTime()); } } finally { IOUtils.closeQuietly(zis); } }
From source file:com.diffplug.gradle.ZipMisc.java
/** * Modifies only the specified entries in a zip file. * * @param input a source from a zip file * @param output an output to a zip file * @param toModify a map from path to an input stream for the entries you'd like to change * @param toOmit a set of entries you'd like to leave out of the zip * @throws IOException/* ww w. ja v a 2s . c om*/ */ public static void modify(ByteSource input, ByteSink output, Map<String, Function<byte[], byte[]>> toModify, Predicate<String> toOmit) throws IOException { try (ZipInputStream zipInput = new ZipInputStream(input.openBufferedStream()); ZipOutputStream zipOutput = new ZipOutputStream(output.openBufferedStream())) { while (true) { // read the next entry ZipEntry entry = zipInput.getNextEntry(); if (entry == null) { break; } Function<byte[], byte[]> replacement = toModify.get(entry.getName()); if (replacement != null) { byte[] clean = ByteStreams.toByteArray(zipInput); byte[] modified = replacement.apply(clean); // if it's the entry being modified, enter the modified stuff try (InputStream replacementStream = new ByteArrayInputStream(modified)) { ZipEntry newEntry = new ZipEntry(entry.getName()); newEntry.setComment(entry.getComment()); newEntry.setExtra(entry.getExtra()); newEntry.setMethod(entry.getMethod()); newEntry.setTime(entry.getTime()); zipOutput.putNextEntry(newEntry); copy(replacementStream, zipOutput); } } else if (!toOmit.test(entry.getName())) { // if it isn't being modified, just copy the file stream straight-up ZipEntry newEntry = new ZipEntry(entry); newEntry.setCompressedSize(-1); zipOutput.putNextEntry(newEntry); copy(zipInput, zipOutput); } // close the entries zipInput.closeEntry(); zipOutput.closeEntry(); } } }
From source file:lucee.commons.io.compress.CompressUtil.java
private static void unzip(Resource zipFile, Resource targetDir) throws IOException { /*if(zipFile instanceof File){ unzip((File)zipFile, targetDir);//from ww w .j a v a2 s . c o m return; }*/ ZipInputStream zis = null; try { zis = new ZipInputStream(IOUtil.toBufferedInputStream(zipFile.getInputStream())); ZipEntry entry; while ((entry = zis.getNextEntry()) != null) { Resource target = targetDir.getRealResource(entry.getName()); if (entry.isDirectory()) { target.mkdirs(); } else { Resource parent = target.getParentResource(); if (!parent.exists()) parent.mkdirs(); IOUtil.copy(zis, target, false); } target.setLastModified(entry.getTime()); zis.closeEntry(); } } finally { IOUtil.closeEL(zis); } }
From source file:slash.navigation.download.actions.Extractor.java
private void handleDirectory(File directory, ZipEntry entry) throws IOException { ensureDirectory(directory.getPath()); setLastModified(directory, fromMillis(entry.getTime())); }
From source file:com.google.gwt.dev.resource.impl.ZipFileResource.java
@Override public long getLastModified() { // XXX < Instantiations ZipEntry entry = getEntry(); if (entry == null) { return -1; }/*from w ww. j a v a 2s. c om*/ // XXX > Instantiations return entry.getTime(); }
From source file:org.jenkins_ci.update_center.model.MavenArtifact.java
public Manifest getManifest() throws IOException { if (manifest == null) { try {//from w w w . j av a 2 s . com JarFile jar = new JarFile(file); ZipEntry e = jar.getEntry("META-INF/MANIFEST.MF"); timestamp = e.getTime(); manifest = jar.getManifest(); jar.close(); } catch (IOException x) { throw (IOException) new IOException("Failed to open " + file).initCause(x); } } return manifest; }
From source file:lucee.commons.io.compress.CompressUtil.java
private static void unzip2(File zipFile, Resource targetDir) throws IOException { ZipFile zf = null;/* ww w . j a v a 2 s. c o m*/ try { zf = new ZipFile(zipFile); ZipEntry entry; Enumeration en = zf.entries(); while (en.hasMoreElements()) { entry = (ZipEntry) en.nextElement(); Resource target = targetDir.getRealResource(entry.getName()); if (entry.isDirectory()) { target.mkdirs(); } else { Resource parent = target.getParentResource(); if (!parent.exists()) parent.mkdirs(); InputStream is = zf.getInputStream(entry); IOUtil.copy(is, target, true); } target.setLastModified(entry.getTime()); } } finally { IOUtil.closeEL(zf); } }
From source file:org.jvnet.hudson.update_center.MavenArtifact.java
public Manifest getManifest() throws IOException { if (manifest == null) { File f = resolve();/*from w w w. j a v a 2 s .co m*/ try { JarFile jar = new JarFile(f); ZipEntry e = jar.getEntry("META-INF/MANIFEST.MF"); timestamp = e.getTime(); manifest = jar.getManifest(); jar.close(); } catch (IOException x) { throw (IOException) new IOException("Failed to open " + f).initCause(x); } } return manifest; }
From source file:org.codice.ddf.configuration.migration.DecryptMigrationManagerImpl.java
@VisibleForTesting void copyToOutputZipFile(ZipEntry entry) { InputStream is = null;//from w w w . j av a 2s.c o m try { final ZipEntry ze = new ZipEntry(entry.getName()); ze.setTime(entry.getTime()); zipOutputStream.putNextEntry(ze); if (!entry.isDirectory()) { is = zip.getInputStream(entry); IOUtils.copy(is, zipOutputStream); } } catch (IOException e) { getReport().record(new MigrationException(Messages.DECRYPT_PATH_ERROR, entry.getName(), e)); } finally { IOUtils.closeQuietly(is); // we do not care about failing to close this stream } }
From source file:com.thoughtworks.go.util.ZipUtilTest.java
@Test void shouldPreserveFileTimestampWhileGeneratingTheZipFile() throws Exception { File file = temporaryFolder.newFile("foo.txt"); file.setLastModified(1297989100000L); // Set this to any date in the past which is greater than the epoch File zip = zipUtil.zip(file, temporaryFolder.newFile("foo.zip"), Deflater.DEFAULT_COMPRESSION); ZipFile actualZip = new ZipFile(zip.getAbsolutePath()); ZipEntry entry = actualZip.getEntry(file.getName()); assertThat(entry.getTime()).isEqualTo(file.lastModified()); }