List of usage examples for java.util.zip ZipInputStream ZipInputStream
public ZipInputStream(InputStream in)
From source file:com.openkm.misc.ZipTest.java
public void testJava() throws IOException { log.debug("testJava()"); File zip = File.createTempFile("java_", ".zip"); // Create zip FileOutputStream fos = new FileOutputStream(zip); ZipOutputStream zos = new ZipOutputStream(fos); zos.putNextEntry(new ZipEntry("coeta")); zos.closeEntry();// w w w . j a va 2 s .c o m zos.close(); // Read zip FileInputStream fis = new FileInputStream(zip); ZipInputStream zis = new ZipInputStream(fis); ZipEntry ze = zis.getNextEntry(); System.out.println(ze.getName()); assertEquals(ze.getName(), "coeta"); zis.close(); }
From source file:net.sf.regain.crawler.preparator.ZipPreparator.java
/** * Prepares the document for indexing// w w w.ja v a 2 s .c o m * * @param rawDocument the document * @throws RegainException if preparation goes wrong */ @Override public void prepare(RawDocument rawDocument) throws RegainException { ArchiveInputStream ain = null; ZipInputStream zipInputStream = new ZipInputStream(rawDocument.getContentAsStream()); PreparatorFactory preparatorFactory = new PreparatorFactory(new DummyCrawlerConfig()); try { ain = new ArchiveStreamFactory().createArchiveInputStream("zip", rawDocument.getContentAsStream()); ZipArchiveEntry entry; while ((entry = (ZipArchiveEntry) ain.getNextEntry()) != null) { String s = String.format("Entry: %s len %d added %TD", entry.getName(), entry.getSize(), new Date(entry.getTime())); System.out.println(s); Preparator preparator = null; ByteArrayOutputStream byteArrayOutputStream = null; RawDocument rawZipDocument = new RawDocument(null, null, null, null); rawZipDocument.setUrl(new File(entry.getName()).toURI().toString()); try { byteArrayOutputStream = new ByteArrayOutputStream(); IOUtils.copy(zipInputStream, byteArrayOutputStream); rawZipDocument.setContent(byteArrayOutputStream.toByteArray()); preparator = preparatorFactory.get(rawZipDocument); } finally { IOUtils.closeQuietly(byteArrayOutputStream); } if (preparator != null) { preparator.prepare(rawZipDocument); // concatenates contents setCleanedContent(new StringBuilder().append(getCleanedContent()).append("\n") .append(preparator.getCleanedContent()).toString()); setTitle(getTitle() + " " + preparator.getTitle()); setSummary(getSummary() + " " + preparator.getSummary()); setCleanedMetaData(getCleanedMetaData() + " " + preparator.getCleanedMetaData()); setHeadlines(getHeadlines() + " " + preparator.getHeadlines()); preparator.cleanUp(); } } } catch (IOException | ArchiveException e) { e.printStackTrace(); } finally { //IOUtils.closeQuietly(zipInputStream); IOUtils.closeQuietly(ain); } }
From source file:com.amalto.core.jobox.util.JoboxUtil.java
public static void extract(String zipPathFile, String destinationPath) throws Exception { FileInputStream fins = new FileInputStream(zipPathFile); ZipInputStream zipInputStream = new ZipInputStream(fins); try {//from ww w. j ava2 s . c om ZipEntry ze; byte ch[] = new byte[256]; while ((ze = zipInputStream.getNextEntry()) != null) { File zipFile = new File(destinationPath + ze.getName()); File zipFilePath = new File(zipFile.getParentFile().getPath()); if (ze.isDirectory()) { if (!zipFile.exists()) { if (!zipFile.mkdirs()) { LOGGER.error("Create folder failed for '" + zipFile.getAbsolutePath() + "'."); //$NON-NLS-1$ //$NON-NLS-2$ } } zipInputStream.closeEntry(); } else { if (!zipFilePath.exists()) { if (!zipFilePath.mkdirs()) { LOGGER.error("Create folder failed for '" + zipFilePath.getAbsolutePath() + "'."); //$NON-NLS-1$ //$NON-NLS-2$ } } FileOutputStream fileOutputStream = new FileOutputStream(zipFile); try { int i; while ((i = zipInputStream.read(ch)) != -1) { fileOutputStream.write(ch, 0, i); } zipInputStream.closeEntry(); } finally { fileOutputStream.close(); } } } } finally { IOUtils.closeQuietly(fins); IOUtils.closeQuietly(zipInputStream); } }
From source file:com.dibsyhex.apkdissector.ZipReader.java
public void getZipContents(String name) { try {/*from w w w .j a v a2s . c o m*/ File file = new File(name); FileInputStream fileInputStream = new FileInputStream(file); ZipInputStream zipInputStream = new ZipInputStream(fileInputStream); //System.out.println(zipInputStream.available()); //System.out.println("Reading each entries in details:"); ZipFile zipFile = new ZipFile(file); ZipEntry zipEntry; response.displayLog("Begining to extract"); while ((zipEntry = zipInputStream.getNextEntry()) != null) { String filename = "extracts" + File.separator + file.getName() + File.separator + zipEntry.getName(); System.out.println(filename); response.displayLog(filename); File extractDirectory = new File(filename); //Create the directories new File(extractDirectory.getParent()).mkdirs(); //Now write the contents InputStream inputStream = zipFile.getInputStream(zipEntry); OutputStream outputStream = new FileOutputStream(extractDirectory); FileUtils.copyInputStreamToFile(inputStream, extractDirectory); //Decode the xml files if (filename.endsWith(".xml")) { //First create a temp file at a location temp/extract/... File temp = new File("temp" + File.separator + extractDirectory); new File(temp.getParent()).mkdirs(); //Create an object of XML Decoder XmlDecoder xmlDecoder = new XmlDecoder(); InputStream inputStreamTemp = new FileInputStream(extractDirectory); byte[] buf = new byte[80000];//increase int bytesRead = inputStreamTemp.read(buf); String xml = xmlDecoder.decompressXML(buf); //System.out.println(xml); FileUtils.writeStringToFile(temp, xml); //Now rewrite the files at the original locations FileUtils.copyFile(temp, extractDirectory); } } response.displayLog("Extraction Done !"); System.out.println(" DONE ! "); zipInputStream.close(); } catch (Exception e) { System.out.println(e.toString()); response.displayError(e.toString()); } }
From source file:com.glaf.jbpm.deploy.MxJbpmProcessDeployer.java
public ProcessDefinition deploy(JbpmContext jbpmContext, byte[] zipBytes) { SAXReader xmlReader = new SAXReader(); JpdlXmlReader jpdlReader = new JpdlXmlReader(); Document doc = null;/* w ww .j a v a2s . co m*/ InputStream inputStream = null; ZipInputStream zipInputStream = null; ProcessDefinition processDefinition = null; Map<String, byte[]> zipMap = null; try { zipInputStream = new ZipInputStream(new ByteArrayInputStream(zipBytes)); zipMap = ZipUtils.getZipBytesMap(zipInputStream); zipInputStream.close(); zipInputStream = null; if (zipMap != null) { if (zipMap.get("processdefinition.xml") != null) { byte[] bytes = zipMap.get("processdefinition.xml"); inputStream = new ByteArrayInputStream(bytes); doc = xmlReader.read(inputStream); jpdlReader.checkTaskNames(doc); this.reconfigProcessDefinition(jbpmContext, doc); Element root = doc.getRootElement(); String encoding = doc.getXMLEncoding(); String processName = root.attributeValue("name"); try { SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss", Locale.getDefault()); String ret = formatter.format(new Date()); String filename = SystemProperties.getConfigRootPath() + "/deploy/" + processName + ret + ".zip"; // ? FileUtils.save(filename, zipBytes); } catch (Exception ex) { if (LogUtils.isDebug()) { logger.debug(ex); ex.printStackTrace(); } } byte[] pdBytes = Dom4jUtils.getBytesFromPrettyDocument(doc, encoding); zipMap.put("processdefinition.xml", pdBytes); // ?? byte[] newZipBytes = ZipUtils.toZipBytes(zipMap); zipInputStream = new ZipInputStream(new ByteArrayInputStream(newZipBytes)); processDefinition = ProcessDefinition.parseParZipInputStream(zipInputStream); jbpmContext.deployProcessDefinition(processDefinition); zipInputStream.close(); zipInputStream = null; String processDefinitionId = String.valueOf(processDefinition.getId()); logger.debug("processDefinitionId:" + processDefinitionId); logger.debug("processName:" + processName); Map<String, Task> taskMap = processDefinition.getTaskMgmtDefinition().getTasks(); if (taskMap != null && taskMap.size() > 0) { Iterator<String> iter = taskMap.keySet().iterator(); while (iter.hasNext()) { String taskName = iter.next(); logger.debug("taskName:" + taskName); } } try { SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss", Locale.getDefault()); String ret = formatter.format(new Date()); String filename = SystemProperties.getConfigRootPath() + "/deploy/" + processName + ret + "_repack.zip"; // ?? FileUtils.save(filename, newZipBytes); } catch (Exception ex) { if (LogUtils.isDebug()) { logger.debug(ex); } } } if (zipMap.get("process.cfg.xml") != null) { byte[] x_bytes = zipMap.get("process.cfg.xml"); if (x_bytes != null) { JbpmExtensionReader reader = new JbpmExtensionReader(); List<Extension> extensions = reader.readTasks(new ByteArrayInputStream(x_bytes)); if (extensions != null && extensions.size() > 0) { JbpmExtensionManager jbpmExtensionManager = ProcessContainer.getContainer() .getJbpmExtensionManager(); jbpmExtensionManager.reconfig(jbpmContext, extensions); } } } } return processDefinition; } catch (Throwable ex) { if (LogUtils.isDebug()) { logger.debug(ex); ex.printStackTrace(); } throw new JbpmException(ex); } finally { try { if (zipInputStream != null) { zipInputStream.close(); zipInputStream = null; } } catch (Exception ex) { if (LogUtils.isDebug()) { logger.debug(ex); } } try { if (inputStream != null) { inputStream.close(); inputStream = null; } } catch (Exception ex) { if (LogUtils.isDebug()) { logger.debug(ex); } } } }
From source file:ch.astina.hesperid.web.services.dbmigration.impl.ClasspathMigrationResolver.java
public Set<Migration> resolve() { Set<Migration> migrations = new HashSet<Migration>(); try {/*from w w w.j ava2 s .co m*/ Enumeration<URL> enumeration = getClass().getClassLoader().getResources(classPath); while (enumeration.hasMoreElements()) { URL url = enumeration.nextElement(); if (url.toExternalForm().startsWith("jar:")) { String file = url.getFile(); file = file.substring(0, file.indexOf("!")); file = file.substring(file.indexOf(":") + 1); InputStream is = new FileInputStream(file); ZipInputStream zip = new ZipInputStream(is); ZipEntry ze; while ((ze = zip.getNextEntry()) != null) { if (!ze.isDirectory() && ze.getName().startsWith(classPath) && ze.getName().endsWith(".sql")) { Resource r = new UrlResource(getClass().getClassLoader().getResource(ze.getName())); String version = versionExtractor.extractVersion(r.getFilename()); migrations.add(migrationFactory.create(version, r)); } } } else { File file = new File(url.getFile()); for (String s : file.list()) { Resource r = new UrlResource(getClass().getClassLoader().getResource(classPath + "/" + s)); String version = versionExtractor.extractVersion(r.getFilename()); migrations.add(migrationFactory.create(version, r)); } } } } catch (Exception e) { logger.error("Error while resolving migrations", e); } return migrations; }
From source file:org.pdfgal.pdfgalweb.utils.impl.ZipUtilsImpl.java
@Override public List<String> saveFilesFromZip(final InputStream inputStream) throws IOException { final List<String> result = new ArrayList<String>(); if (inputStream != null) { final ZipInputStream zis = new ZipInputStream(inputStream); ZipEntry entry = zis.getNextEntry(); while (entry != null) { final byte[] buffer = new byte[1024]; final String fileName = this.fileUtils.getAutogeneratedName(entry.getName()); final File file = new File(fileName); final FileOutputStream fos = new FileOutputStream(file); int len; while ((len = zis.read(buffer)) > 0) { fos.write(buffer, 0, len); }/* w w w .ja va2 s . com*/ fos.close(); result.add(fileName); entry = zis.getNextEntry(); } zis.closeEntry(); zis.close(); } return result; }
From source file:com.ikon.module.common.CommonWorkflowModule.java
/** * Register Process Definition//from w w w .j a v a 2 s .co m */ public static void registerProcessDefinition(InputStream is) throws WorkflowException, ParseException, IOException { log.debug("registerProcessDefinition({})", is); JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext(); InputStream isForms = null; ZipInputStream zis = null; if (Config.SYSTEM_READONLY) { throw new WorkflowException("System is in read-only mode"); } try { zis = new ZipInputStream(is); org.jbpm.graph.def.ProcessDefinition processDefinition = org.jbpm.graph.def.ProcessDefinition .parseParZipInputStream(zis); // Check xml form definition FileDefinition fileDef = processDefinition.getFileDefinition(); isForms = fileDef.getInputStream("forms.xml"); FormUtils.parseWorkflowForms(isForms); // If it is ok, deploy it jbpmContext.deployProcessDefinition(processDefinition); } catch (JbpmException e) { throw new WorkflowException(e.getMessage(), e); } finally { IOUtils.closeQuietly(isForms); IOUtils.closeQuietly(zis); jbpmContext.close(); } log.debug("registerProcessDefinition: void"); }
From source file:com.glaf.activiti.web.springmvc.ActivitiDeployController.java
/** * //from w w w. j av a 2s . c o m * @param model * @param mFile * @return * @throws IOException */ @RequestMapping(method = RequestMethod.POST) public String processSubmit(Model model, @RequestParam("file") MultipartFile mFile) throws IOException { if (!mFile.isEmpty()) { String deploymentId = null; ProcessDefinition processDefinition = null; if (mFile.getOriginalFilename().endsWith(".zip") || mFile.getOriginalFilename().endsWith(".jar")) { ZipInputStream zipInputStream = null; try { zipInputStream = new ZipInputStream(mFile.getInputStream()); deploymentId = activitiDeployService.addZipInputStream(zipInputStream).getId(); } finally { IOUtils.closeStream(zipInputStream); } } else { String resourceName = FileUtils.getFilename(mFile.getOriginalFilename()); deploymentId = activitiDeployService.addInputStream(resourceName, mFile.getInputStream()).getId(); } if (StringUtils.isNotEmpty(deploymentId)) { logger.debug("deploymentId:" + deploymentId); processDefinition = activitiProcessQueryService.getProcessDefinitionByDeploymentId(deploymentId); if (processDefinition != null) { model.addAttribute("processDefinition", processDefinition); model.addAttribute("deploymentId", processDefinition.getDeploymentId()); String resourceName = processDefinition.getDiagramResourceName(); if (resourceName != null) { ProcessUtils.saveProcessImageToFileSystem(processDefinition); String path = "/deploy/bpmn/" + ProcessUtils.getImagePath(processDefinition); model.addAttribute("path", path); return "/activiti/deploy/showImage"; } } } } String view = ViewProperties.getString("activiti.deploy"); if (StringUtils.isNotEmpty(view)) { return view; } return "/activiti/deploy/deploy"; }
From source file:be.fedict.eid.applet.service.signer.odf.ODFSignatureFacet.java
public void preSign(XMLSignatureFactory signatureFactory, Document document, String signatureId, List<X509Certificate> signingCertificateChain, List<Reference> references, List<XMLObject> objects) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { try {/*from w w w .j a va2 s . c o m*/ URL odfUrl = this.signatureService.getOpenDocumentURL(); InputStream odfInputStream = odfUrl.openStream(); ZipInputStream odfZipInputStream = new ZipInputStream(odfInputStream); ZipEntry zipEntry; DigestMethod digestMethod = signatureFactory.newDigestMethod(this.digestAlgo.getXmlAlgoId(), null); while (null != (zipEntry = odfZipInputStream.getNextEntry())) { if (ODFUtil.isToBeSigned(zipEntry)) { String name = zipEntry.getName(); /* * Whitespaces are illegal in URIs * * Note that OOo 3.0/3.1 seems to have a bug, seems like the * OOo signature verification doesn't convert it back to * whitespace, to be investigated */ String uri = name.replaceAll(" ", "%20"); Reference reference; if (name.endsWith(".xml") && !isEmpty(odfZipInputStream)) { /* apply transformation on non-empty XML files only */ List<Transform> transforms = new LinkedList<Transform>(); Transform transform = signatureFactory.newTransform(CanonicalizationMethod.INCLUSIVE, (TransformParameterSpec) null); transforms.add(transform); reference = signatureFactory.newReference(uri, digestMethod, transforms, null, null); } else { reference = signatureFactory.newReference(uri, digestMethod); } references.add(reference); LOG.debug("entry: " + name); } } } catch (IOException e) { LOG.error("IO error: " + e.getMessage(), e); } catch (Exception e) { LOG.error("Error: " + e.getMessage(), e); } }