List of usage examples for org.apache.commons.compress.archivers.zip ZipArchiveEntry getLastModifiedDate
public Date getLastModifiedDate()
From source file:com.kalix.tools.kibana.KibanaController.java
/** * download kibana from remote server/*from w w w . j a v a 2 s . c o m*/ * * @throws Exception */ public void download() throws Exception { File target = new File(workingDirectory, KIBANA_FOLDER); if (target.exists()) { LOGGER.warn("Kibana folder already exists, download is skipped"); return; } LOGGER.debug("Downloading Kibana from {}", KIBANA_LOCATION); if (isWindows()) { try (ZipArchiveInputStream inputStream = new ZipArchiveInputStream( new URL(KIBANA_LOCATION).openStream())) { ZipArchiveEntry entry; while ((entry = (ZipArchiveEntry) inputStream.getNextEntry()) != null) { File file = new File(workingDirectory, entry.getName()); if (entry.isDirectory()) { file.mkdirs(); } else { int read; byte[] buffer = new byte[4096]; try (FileOutputStream outputStream = new FileOutputStream(file)) { while ((read = inputStream.read(buffer, 0, 4096)) != -1) { outputStream.write(buffer, 0, read); } } } } } } else { try (GzipCompressorInputStream gzInputStream = new GzipCompressorInputStream( new URL(KIBANA_LOCATION).openStream())) { try (TarArchiveInputStream inputStream = new TarArchiveInputStream(gzInputStream)) { TarArchiveEntry entry; while ((entry = (TarArchiveEntry) inputStream.getNextEntry()) != null) { File file = new File(workingDirectory, entry.getName()); if (entry.isDirectory()) { file.mkdirs(); } else { int read; byte[] buffer = new byte[4096]; try (FileOutputStream outputStream = new FileOutputStream(file)) { while ((read = inputStream.read(buffer, 0, 4096)) != -1) { outputStream.write(buffer, 0, read); } } file.setLastModified(entry.getLastModifiedDate().getTime()); if (entry instanceof TarArchiveEntry) { int mode = ((TarArchiveEntry) entry).getMode(); if ((mode & 00100) > 0) { file.setExecutable(true, (mode & 00001) == 0); } } } } } } } overrideConfig(); }
From source file:org.abysm.onionzip.ZipFileExtractHelper.java
void listZipArchiveEntries() throws IOException { ZipFile zipFile = new ZipFile(zipFilename, encoding); try {//from w ww . j ava 2s . c o m System.out.println("Length\tDatetime\tName\tEFS\tUnix Mode"); for (Enumeration<ZipArchiveEntry> zipArchiveEntryEnumeration = zipFile .getEntries(); zipArchiveEntryEnumeration.hasMoreElements();) { ZipArchiveEntry entry = zipArchiveEntryEnumeration.nextElement(); System.out.format("%d\t%s\t%s\t%b\t%o\n", entry.getSize(), entry.getLastModifiedDate().toString(), entry.getName(), entry.getGeneralPurposeBit().usesUTF8ForNames(), entry.getUnixMode()); } } finally { ZipFile.closeQuietly(zipFile); } }
From source file:org.abysm.onionzip.ZipFileExtractHelper.java
void extractZipArchiveEntries() throws IOException { ZipFile zipFile = new ZipFile(zipFilename, encoding); try {// w w w .j a va 2s .c o m for (Enumeration<ZipArchiveEntry> zipArchiveEntryEnumeration = zipFile .getEntries(); zipArchiveEntryEnumeration.hasMoreElements();) { ZipArchiveEntry entry = zipArchiveEntryEnumeration.nextElement(); System.out.println(entry.getName()); if (entry.isDirectory()) { Path directory = Paths.get(entry.getName()); Files.createDirectories(directory); } else if (entry.isUnixSymlink()) { Path symlink = Paths.get(entry.getName()); Path parentDirectory = symlink.getParent(); Path target = Paths.get(zipFile.getUnixSymlink(entry)); if (parentDirectory != null) { Files.createDirectories(parentDirectory); } Files.createSymbolicLink(symlink, target); } else { Path file = Paths.get(entry.getName()); Path parentDirectory = file.getParent(); if (parentDirectory != null) { Files.createDirectories(parentDirectory); } InputStream contentInputStream = zipFile.getInputStream(entry); FileOutputStream extractedFileOutputStream = new FileOutputStream(entry.getName()); try { IOUtils.copy(contentInputStream, extractedFileOutputStream); } finally { IOUtils.closeQuietly(contentInputStream); IOUtils.closeQuietly(extractedFileOutputStream); } FileTime fileTime = FileTime.fromMillis(entry.getLastModifiedDate().getTime()); Files.setLastModifiedTime(file, fileTime); } } } finally { ZipFile.closeQuietly(zipFile); } }
From source file:org.apache.karaf.decanter.kibana6.KibanaController.java
public void download() throws Exception { File target = new File(workingDirectory, KIBANA_FOLDER); if (target.exists()) { LOGGER.warn("Kibana folder already exists, download is skipped"); return;/*w w w. j a v a2 s.co m*/ } LOGGER.debug("Downloading Kibana from {}", KIBANA_LOCATION); if (isWindows()) { try (ZipArchiveInputStream inputStream = new ZipArchiveInputStream( new URL(KIBANA_LOCATION).openStream())) { ZipArchiveEntry entry; while ((entry = (ZipArchiveEntry) inputStream.getNextEntry()) != null) { File file = new File(workingDirectory, entry.getName()); if (entry.isDirectory()) { file.mkdirs(); } else { int read; byte[] buffer = new byte[4096]; try (FileOutputStream outputStream = new FileOutputStream(file)) { while ((read = inputStream.read(buffer, 0, 4096)) != -1) { outputStream.write(buffer, 0, read); } } } } } } else { try (GzipCompressorInputStream gzInputStream = new GzipCompressorInputStream( new URL(KIBANA_LOCATION).openStream())) { try (TarArchiveInputStream inputStream = new TarArchiveInputStream(gzInputStream)) { TarArchiveEntry entry; while ((entry = (TarArchiveEntry) inputStream.getNextEntry()) != null) { File file = new File(workingDirectory, entry.getName()); if (entry.isDirectory()) { file.mkdirs(); } else { int read; byte[] buffer = new byte[4096]; try (FileOutputStream outputStream = new FileOutputStream(file)) { while ((read = inputStream.read(buffer, 0, 4096)) != -1) { outputStream.write(buffer, 0, read); } } file.setLastModified(entry.getLastModifiedDate().getTime()); if (entry instanceof TarArchiveEntry) { int mode = ((TarArchiveEntry) entry).getMode(); if ((mode & 00100) > 0) { file.setExecutable(true, (mode & 00001) == 0); } } } } } } } overrideConfig(); }