List of usage examples for org.apache.commons.compress.archivers.zip ZipFile getEntry
public ZipArchiveEntry getEntry(String name)
null
if no entry by that name exists. From source file:org.springframework.ide.eclipse.boot.wizard.content.ZipFileCodeSet.java
@Override public <T> T readFileEntry(String path, Processor<T> processor) throws Exception { ZipFile zip = new ZipFile(zipDownload.getFile()); try {/* ww w.j av a 2 s . co m*/ String entryName = root.append(path).toString(); ZipArchiveEntry entry = zip.getEntry(entryName); return processor.doit(entry == null ? null : csEntry(zip, entry)); } finally { try { zip.close(); } catch (IOException e) { } } }
From source file:org.xwiki.wiki.workspacesmigrator.internal.DefaultDocumentRestorerFromAttachedXAR.java
@Override public void restoreDocumentFromAttachedXAR(DocumentReference docReference, String attachmentName, List<DocumentReference> documentsToRestore) throws XWikiException { XWikiContext xcontext = xcontextProvider.get(); XWiki xwiki = xcontext.getWiki();//from w w w . j av a 2 s . co m File tempZipFile = null; try { tempZipFile = getTemporaryZipFile(docReference, attachmentName); if (tempZipFile == null) { return; } ZipFile zipFile = new ZipFile(tempZipFile); // We look for each document to restore if there is a corresponding zipEntry. Iterator<DocumentReference> itDocumentsToRestore = documentsToRestore.iterator(); while (itDocumentsToRestore.hasNext()) { DocumentReference docRef = itDocumentsToRestore.next(); // Compute what should be the filename of the document to restore String fileNameToRestore = String.format("%s/%s.xml", docRef.getLastSpaceReference().getName(), docRef.getName()); // Get the corresponding zip Entry ZipArchiveEntry zipEntry = zipFile.getEntry(fileNameToRestore); if (zipEntry != null) { // Restore the document XWikiDocument docToRestore = xwiki.getDocument(docRef, xcontext); docToRestore.fromXML(zipFile.getInputStream(zipEntry)); xwiki.saveDocument(docToRestore, xcontext); // We have restored this document itDocumentsToRestore.remove(); } } zipFile.close(); } catch (IOException e) { logger.error("Error during the decompression of [{}].", attachmentName, e); } finally { // Delete the temporary zip file if (tempZipFile != null) { tempZipFile.delete(); } } }