List of usage examples for java.util.zip ZipInputStream getNextEntry
public ZipEntry getNextEntry() throws IOException
From source file:com.comcast.magicwand.spells.web.chrome.ChromePhoenixDriver.java
private void extractZip(File sourceZipFile, String destinationDir) throws IOException { LOG.debug("Extracting [{}] to dir [{}]", sourceZipFile, destinationDir); ZipInputStream zis = null; ZipEntry entry;/*from www .j a v a 2s. c o m*/ try { zis = new ZipInputStream(FileUtils.openInputStream(sourceZipFile)); while (null != (entry = zis.getNextEntry())) { File dst = Paths.get(destinationDir, entry.getName()).toFile(); FileOutputStream output = FileUtils.openOutputStream(dst); try { IOUtils.copy(zis, output); output.close(); } finally { IOUtils.closeQuietly(output); } } zis.close(); } finally { IOUtils.closeQuietly(zis); } }
From source file:com.github.nethad.clustermeister.provisioning.local.JPPFLocalNode.java
private void unzipNode(InputStream fileToUnzip, File targetDir) { ZipInputStream zipFile; try {/*from ww w . j a va2s .c o m*/ zipFile = new ZipInputStream(fileToUnzip); ZipEntry entry; while ((entry = zipFile.getNextEntry()) != null) { // ZipEntry entry = (ZipEntry) entries.nextElement(); if (entry.isDirectory()) { // Assume directories are stored parents first then children. System.err.println("Extracting directory: " + entry.getName()); // This is not robust, just for demonstration purposes. (new File(targetDir, entry.getName())).mkdir(); continue; } System.err.println("Extracting file: " + entry.getName()); File targetFile = new File(targetDir, entry.getName()); copyInputStream_notClosing(zipFile, new BufferedOutputStream(new FileOutputStream(targetFile))); // zipFile.closeEntry(); } zipFile.close(); } catch (IOException ioe) { logger.warn("Unhandled exception.", ioe); } }
From source file:aurelienribon.gdxsetupui.ProjectUpdate.java
/** * Selected libraries are inflated from their zip files, and put in the * correct folders of the projects./*from w w w .j a va 2 s.c o m*/ * @throws IOException */ public void inflateLibraries() throws IOException { File commonPrjLibsDir = new File(Helper.getCorePrjPath(cfg) + "libs"); File desktopPrjLibsDir = new File(Helper.getDesktopPrjPath(cfg) + "libs"); File androidPrjLibsDir = new File(Helper.getAndroidPrjPath(cfg) + "libs"); File htmlPrjLibsDir = new File(Helper.getHtmlPrjPath(cfg) + "war/WEB-INF/lib"); File iosPrjLibsDir = new File(Helper.getIosPrjPath(cfg) + "libs"); File dataDir = new File(Helper.getAndroidPrjPath(cfg) + "assets"); for (String library : cfg.libraries) { InputStream is = new FileInputStream(cfg.librariesZipPaths.get(library)); ZipInputStream zis = new ZipInputStream(is); ZipEntry entry; LibraryDef def = libs.getDef(library); while ((entry = zis.getNextEntry()) != null) { if (entry.isDirectory()) continue; String entryName = entry.getName(); for (String elemName : def.libsCommon) if (entryName.endsWith(elemName)) copyEntry(zis, elemName, commonPrjLibsDir); if (cfg.isDesktopIncluded) { for (String elemName : def.libsDesktop) if (entryName.endsWith(elemName)) copyEntry(zis, elemName, desktopPrjLibsDir); } if (cfg.isAndroidIncluded) { for (String elemName : def.libsAndroid) if (entryName.endsWith(elemName)) copyEntry(zis, elemName, androidPrjLibsDir); for (String elemName : def.data) if (entryName.endsWith(elemName)) copyEntry(zis, elemName, dataDir); } if (cfg.isHtmlIncluded) { for (String elemName : def.libsHtml) if (entryName.endsWith(elemName)) copyEntry(zis, elemName, htmlPrjLibsDir); } if (cfg.isIosIncluded) { for (String elemName : def.libsIos) if (entryName.endsWith(elemName)) copyEntry(zis, elemName, iosPrjLibsDir); } } zis.close(); } }
From source file:com.bibisco.manager.ProjectManager.java
public static void unZipIt(String pStrZipFile) { mLog.debug("Start unZipIt(String)"); try {// www .j ava2s. c o m // get temp directory path String lStrTempDirectory = ContextManager.getInstance().getTempDirectoryPath(); // get the zip file content ZipInputStream lZipInputStream = new ZipInputStream(new FileInputStream(pStrZipFile)); // get the zipped file list entry ZipEntry lZipEntry = lZipInputStream.getNextEntry(); while (lZipEntry != null) { String lStrFileName = lZipEntry.getName(); File lFileZipEntry = new File(lStrTempDirectory + File.separator + lStrFileName); // create all non exists folders new File(lFileZipEntry.getParent()).mkdirs(); FileOutputStream lFileOutputStream = new FileOutputStream(lFileZipEntry); byte[] buffer = new byte[1024]; int lIntLen; while ((lIntLen = lZipInputStream.read(buffer)) > 0) { lFileOutputStream.write(buffer, 0, lIntLen); } lFileOutputStream.close(); lZipEntry = lZipInputStream.getNextEntry(); } lZipInputStream.closeEntry(); lZipInputStream.close(); } catch (IOException e) { mLog.error(e); throw new BibiscoException(e, BibiscoException.IO_EXCEPTION); } mLog.debug("End unZipIt(String)"); }
From source file:com.zimbra.qa.unittest.TestUserServlet.java
private void verifyZipFile(ZMailbox mbox, String relativePath, boolean hasBody) throws Exception { InputStream in = mbox.getRESTResource(relativePath); ZipInputStream zipIn = new ZipInputStream(in); ZipEntry entry;/*from w w w.ja v a2 s . co m*/ boolean foundMessage = false; while ((entry = zipIn.getNextEntry()) != null) { if (entry.getName().endsWith(".eml")) { ByteArrayOutputStream buf = new ByteArrayOutputStream(); ByteUtil.copy(zipIn, false, buf, true); byte[] content = buf.toByteArray(); MimeMessage message = new ZMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content)); byte[] body = ByteUtil.getContent(message.getInputStream(), 0); if (hasBody) { assertTrue(entry.getName() + " has no body", body.length > 0); } else { assertEquals(entry.getName() + " has a body", 0, body.length); } foundMessage = true; } } zipIn.close(); assertTrue(foundMessage); }
From source file:io.sledge.core.impl.extractor.SledgeApplicationPackageExtractor.java
@Override public List<String> getEnvironmentNames(ApplicationPackage appPackage) { List<String> envFiles = new ArrayList<>(); ZipInputStream zipStream = getNewUtf8ZipInputStream(appPackage); try {/*from w w w.ja va2s. c o m*/ ZipEntry zipEntry = null; while ((zipEntry = zipStream.getNextEntry()) != null) { if (zipEntry.isDirectory()) { zipStream.closeEntry(); continue; } if (zipEntry.getName().startsWith("environments/")) { // test-publish.properties -> test-publish envFiles.add(getBaseName(zipEntry.getName())); zipStream.closeEntry(); } } } catch (IOException e) { log.error(e.getMessage(), e); } finally { try { zipStream.close(); appPackage.getPackageFile().reset(); } catch (IOException e) { log.error(e.getMessage(), e); } } return envFiles; }
From source file:com.boundlessgeo.geoserver.bundle.BundleExporterTest.java
@Test public void testZipBundle() throws Exception { new CatalogCreator(cat).workspace("foo"); exporter = new BundleExporter(cat, new ExportOpts(cat.getWorkspaceByName("foo")).name("blah")); exporter.run();//ww w. j a va 2 s . co m Path zip = exporter.zip(); ZipInputStream zin = new ZipInputStream( new ByteArrayInputStream(FileUtils.readFileToByteArray(zip.toFile()))); ZipEntry entry = null; boolean foundBundle = false; boolean foundWorkspace = false; while (((entry = zin.getNextEntry()) != null)) { if (entry.getName().equals("bundle.json")) { foundBundle = true; } if (entry.getName().endsWith("workspace.xml")) { foundWorkspace = true; } } assertTrue(foundBundle); assertTrue(foundWorkspace); }
From source file:hd3gtv.embddb.network.DataBlock.java
/** * Import mode/*w w w .j a v a 2 s. com*/ */ DataBlock(Protocol protocol, byte[] request_raw_datas) throws IOException { if (log.isTraceEnabled()) { log.trace("Get raw datas" + Hexview.LINESEPARATOR + Hexview.tracelog(request_raw_datas)); } ByteArrayInputStream inputstream_client_request = new ByteArrayInputStream(request_raw_datas); DataInputStream dis = new DataInputStream(inputstream_client_request); byte[] app_socket_header_tag = new byte[Protocol.APP_SOCKET_HEADER_TAG.length]; dis.readFully(app_socket_header_tag, 0, Protocol.APP_SOCKET_HEADER_TAG.length); if (Arrays.equals(Protocol.APP_SOCKET_HEADER_TAG, app_socket_header_tag) == false) { throw new IOException("Protocol error with app_socket_header_tag"); } int version = dis.readInt(); if (version != Protocol.VERSION) { throw new IOException( "Protocol error with version, this = " + Protocol.VERSION + " and dest = " + version); } byte tag = dis.readByte(); if (tag != 0) { throw new IOException("Protocol error, can't found request_name raw datas"); } int size = dis.readInt(); if (size < 1) { throw new IOException( "Protocol error, can't found request_name raw datas size is too short (" + size + ")"); } byte[] request_name_raw = new byte[size]; dis.read(request_name_raw); request_name = new String(request_name_raw, Protocol.UTF8); tag = dis.readByte(); if (tag != 1) { throw new IOException("Protocol error, can't found zip raw datas"); } entries = new ArrayList<>(1); ZipInputStream request_zip = new ZipInputStream(dis); ZipEntry entry; while ((entry = request_zip.getNextEntry()) != null) { entries.add(new RequestEntry(entry, request_zip)); } request_zip.close(); }
From source file:be.fedict.eid.dss.document.zip.ZIPDSSDocumentService.java
public DocumentVisualization findDocument(byte[] parentDocument, String resourceId) throws Exception { ZipInputStream zipInputStream = new ZipInputStream(new ByteArrayInputStream(parentDocument)); ZipEntry zipEntry;//from ww w . j a v a 2s . c om while (null != (zipEntry = zipInputStream.getNextEntry())) { if (getResourceId(zipEntry).equals(resourceId)) { LOG.debug("Found file: " + resourceId); byte[] data = IOUtils.toByteArray(zipInputStream); return new DocumentVisualization(new MimetypesFileTypeMap().getContentType(zipEntry.getName()), data); } } return null; }
From source file:gov.nih.nci.caarray.application.project.FileUploadUtils.java
/** * Unpack the given file, which must be a ZIP file, and add its files individually to the given project and save * them in the data store. If any file within the ZIP file has the same name as a file already belonging to the * project, it will not be added to the project. If any file within one of the ZIP files is itself a ZIP file, it * will be added to the project, and will not recursively unpacked. The ZIP file must not contain directories. If it * does, an InvalidFileException will be thrown. * @param project the project to which the unpacked files should be added. * @param fileName the name of the file being unpacked. * @param inputStream the InputStream object which points to the File data * * @return a result object with information about number of files actually added to the project and conflicting * files//w w w .j a va 2s . co m * @throws InvalidFileException if any file within the ZIP file is within a subdirectory, or if there is an error * adding any file to the project. */ private void unpackFile(Project project, String fileName, InputStream inputStream) throws InvalidFileException { ZipInputStream zipStream = null; try { zipStream = new ZipInputStream(inputStream); ZipEntry entry = zipStream.getNextEntry(); final Set<String> existingFileNames = new HashSet<String>(project.getFileNames()); while (entry != null) { String entryName = entry.getName(); checkForDirectory(entry); if (!checkAlreadyAdded(existingFileNames, entryName)) { addEntryToProject(project, zipStream, entryName); existingFileNames.add(entryName); } entry = zipStream.getNextEntry(); } } catch (final IOException e) { throw new InvalidFileException(fileName, UNPACKING_ERROR_KEY, result, UNPACKING_ERROR_MESSAGE, e); } catch (final InvalidFileException e) { throw new InvalidFileException(fileName, UNPACKING_ERROR_KEY, result, UNPACKING_ERROR_MESSAGE, e); } finally { IOUtils.closeQuietly(zipStream); IOUtils.closeQuietly(inputStream); } }