List of usage examples for java.util.zip ZipInputStream ZipInputStream
public ZipInputStream(InputStream in)
From source file:org.apache.geode.geospatial.client.Roads.java
/** * Load the roads from a file. The roads loaded will be added to the set of roads. * * The loaded will add in a bi-directional path. * * Assumes the roads will be defined in a KMZ file. * * @param roadsFileName//from ww w .j a v a 2 s . co m * @throws IOException * @throws ParserConfigurationException * @throws SAXException */ public void setRoads(String roadsFileName) throws IOException, ParserConfigurationException, SAXException { SimpleFeature featureSet = null; try (ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(new File(roadsFileName)))) { for (ZipEntry zipEntry = zipInputStream.getNextEntry(); zipEntry != null; zipEntry = zipInputStream .getNextEntry()) { if (zipEntry.getName().toLowerCase().endsWith(".kml")) { KMLConfiguration kmlConfiguration = new KMLConfiguration(); Parser parser = new Parser(kmlConfiguration); featureSet = (SimpleFeature) parser.parse(zipInputStream); //just one KML feature and we punch out. break; } } } notNull(featureSet, "Didn't find any features in " + roadsFileName); ArrayList<Geometry> geometries = new ArrayList<>(); findAllGeometries(geometries, featureSet); addRoads(geometries); ArrayList<Geometry> reverse = new ArrayList<>(); for (Geometry curr : geometries) { Coordinate[] toReverse = Arrays.copyOf(curr.getCoordinates(), curr.getCoordinates().length); CollectionUtils.reverseArray(toReverse); reverse.add(geometryFactory.createLineString(toReverse)); } addRoads(reverse); }
From source file:com.googlecode.dex2jar.reader.DexFileReader.java
/** * read the dex file from byte array, if the byte array is a zip stream, it will return the content of classes.dex * in the zip stream.//from ww w .j a v a 2s.c o m * * @param data * @return * @throws IOException */ public static byte[] readDex(byte[] data) throws IOException { if ("de".equals(new String(data, 0, 2))) {// dex/y return data; } else if ("PK".equals(new String(data, 0, 2))) {// ZIP ZipInputStream zis = null; try { zis = new ZipInputStream(new ByteArrayInputStream(data)); for (ZipEntry entry = zis.getNextEntry(); entry != null; entry = zis.getNextEntry()) { if (entry.getName().equals("classes.dex")) { return IOUtils.toByteArray(zis); } } } finally { IOUtils.closeQuietly(zis); } } throw new RuntimeException("the src file not a .dex, .odex or zip file"); }
From source file:com.facebook.buck.android.AaptPackageResourcesIntegrationTest.java
@Test public void testAaptPackageIsScrubbed() throws IOException { AssumeAndroidPlatform.assumeSdkIsAvailable(); workspace.runBuckBuild(MAIN_BUILD_TARGET).assertSuccess(); Path aaptOutput = workspace.getPath(BuildTargets.getGenPath(filesystem, BuildTargetFactory.newInstance(MAIN_BUILD_TARGET) .withFlavors(AndroidBinaryGraphEnhancer.AAPT_PACKAGE_FLAVOR), AaptPackageResources.RESOURCE_APK_PATH_FORMAT)); Date dosEpoch = new Date(ZipUtil.dosToJavaTime(ZipConstants.DOS_FAKE_TIME)); try (ZipInputStream is = new ZipInputStream(new FileInputStream(aaptOutput.toFile()))) { for (ZipEntry entry = is.getNextEntry(); entry != null; entry = is.getNextEntry()) { assertThat(entry.getName(), new Date(entry.getTime()), Matchers.equalTo(dosEpoch)); }/*from ww w . j a va2 s . c om*/ } }
From source file:com.celements.photo.utilities.Unzip.java
private ZipInputStream getZipInputStream(byte[] srcFile) { ByteArrayInputStream in = new ByteArrayInputStream(srcFile); return new ZipInputStream(new BufferedInputStream(in)); }
From source file:com.sg2net.utilities.ListaCAP.ListaComuniCapFromInternet.java
public Collection<Comune> donwloadAndParse() { try {// w w w .j a v a 2 s. c o m List<Comune> comuni = new ArrayList<>(); HttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet(ZIP_URL); HttpResponse response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); if (entity != null) { try (InputStream instream = entity.getContent();) { ZipInputStream zipInputStream = new ZipInputStream(instream); ZipEntry entry = zipInputStream.getNextEntry(); if (entry != null) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); byte data[] = new byte[BUFFER]; int count = 0; while ((count = zipInputStream.read(data, 0, BUFFER)) != -1) { outputStream.write(data, 0, count); } StringReader reader = new StringReader( new String(outputStream.toByteArray(), HTML_ENCODING)); LineNumberReader lineReader = new LineNumberReader(reader); String line; int lineNumber = 0; while ((line = lineReader.readLine()) != null) { logger.trace("line " + (lineNumber + 1) + " from zip file=" + line); if (lineNumber > 0) { String[] values = line.split(";"); if (values.length >= 9) { Comune comune = new Comune(values[CODICE_ISTAT_POS], values[CODICE_CATASTALE_POS], values[NOME_POS], values[PROVINCIA_POS]); comuni.add(comune); String capStr = values[CAP_POS]; Collection<String> capList; if (capStr.endsWith("x")) { capList = getListaCAPFromHTMLPage(values[URL_COMUNE_POS]); } else { capList = new HashSet<>(); capList.add(capStr); } comune.setCodiciCap(capList); } } lineNumber++; } } } } return comuni; } catch (IOException e) { logger.error(e.getMessage(), e); throw new RuntimeException(e.getMessage(), e); } }
From source file:com.sany.workflow.action.ActivitiRepositoryAction.java
/** * ?// ww w . j a v a 2s . c o m * @param processDeployment * @return String */ public @ResponseBody String deployProcess(ProcessDeployment processDeployment, String needConfig) { String result = "success"; TransactionManager tm = new TransactionManager(); try { tm.begin(); Deployment deployment = null; if (processDeployment.getProcessDef().getOriginalFilename().endsWith(".zip") || processDeployment.getProcessDef().getContentType().contains(FILE_TYPE_ZIP)) { deployment = activitiService.deployProcDefByZip(processDeployment.getNAME_(), new ZipInputStream(processDeployment.getProcessDef().getInputStream()), processDeployment.getUpgradepolicy()); } else { deployment = activitiService.deployProcDefByInputStream(processDeployment.getNAME_(), processDeployment.getProcessDef().getOriginalFilename(), processDeployment.getProcessDef().getInputStream(), processDeployment.getUpgradepolicy()); } if (deployment != null) { ProcessDef pd = activitiService.getProcessDefByDeploymentId(deployment.getId()); if (needConfig.equals("1")) { activitiConfigService .addActivitiNodeInfo(activitiService.getPorcessKeyByDeployMentId(deployment.getId())); } else activitiConfigService.updateActivitiNodeInfo( activitiService.getPorcessKeyByDeployMentId(deployment.getId()), processDeployment.getUpgradepolicy()); if (!processDeployment.getParamFile().isEmpty()) { result = activitiConfigService.addNodeParams(processDeployment.getParamFile().getInputStream(), pd.getKEY_()); } if (pd != null) { activitiConfigService.addProBusinessType(pd.getKEY_(), processDeployment.getBusinessTypeId()); activitiRelationService.addAppProcRelation(pd, processDeployment.getWf_app_id()); // ???/??0 activitiService.addIsContainHoliday(pd.getKEY_(), 0); } if (processDeployment.getUpgradepolicy() == DeploymentBuilder.Deploy_policy_delete)// { activitiService.deleteTodoListByKeyWithTrigger(pd.getKEY_()); } } tm.commit(); return result; } catch (Exception e) { logger.error(e); try { tm.rollback(); } catch (RollbackException e1) { // TODO Auto-generated catch block logger.error(e1); } return StringUtil.exceptionToString(e); } finally { tm.release(); } }
From source file:mSearch.filmlisten.FilmlisteLesen.java
private InputStream selectDecompressor(String source, InputStream in) throws Exception { if (source.endsWith(Const.FORMAT_XZ)) { in = new XZInputStream(in); } else if (source.endsWith(Const.FORMAT_ZIP)) { ZipInputStream zipInputStream = new ZipInputStream(in); zipInputStream.getNextEntry();//from w ww.j a v a 2s. c om in = zipInputStream; } return in; }
From source file:fedora.server.storage.translation.AtomDODeserializer.java
/** * {@inheritDoc}/*w w w . ja va 2s .c o m*/ */ public void deserialize(InputStream in, DigitalObject obj, String encoding, int transContext) throws ObjectIntegrityException, StreamIOException, UnsupportedEncodingException { if (m_format.equals(ATOM_ZIP1_1)) { try { m_tempDir = FileUtils.createTempDir("atomzip", null); m_zin = new ZipInputStream(new BufferedInputStream(in)); ZipEntry entry; while ((entry = m_zin.getNextEntry()) != null) { FileUtils.copy(m_zin, new FileOutputStream(new File(m_tempDir, entry.getName()))); } in = new FileInputStream(new File(m_tempDir, "atommanifest.xml")); } catch (FileNotFoundException e) { throw new StreamIOException(e.getMessage(), e); } catch (IOException e) { throw new StreamIOException(e.getMessage(), e); } } Parser parser = abdera.getParser(); Document<Feed> feedDoc = parser.parse(in); m_feed = feedDoc.getRoot(); m_xpath = abdera.getXPath(); m_obj = obj; m_encoding = encoding; m_transContext = transContext; addObjectProperties(); addDatastreams(); DOTranslationUtility.normalizeDatastreams(m_obj, m_transContext, m_encoding); FileUtils.delete(m_tempDir); }
From source file:be.fedict.eid.dss.document.odf.ODFDSSDocumentService.java
@Override public List<SignatureInfo> verifySignatures(byte[] document, byte[] originalDocument) throws Exception { List<SignatureInfo> signatureInfos = new LinkedList<SignatureInfo>(); ZipInputStream odfZipInputStream = new ZipInputStream(new ByteArrayInputStream(document)); ZipEntry zipEntry;//from w ww .j a va 2 s . c o m while (null != (zipEntry = odfZipInputStream.getNextEntry())) { if (ODFUtil.isSignatureFile(zipEntry)) { Document documentSignatures = ODFUtil.loadDocument(odfZipInputStream); NodeList signatureNodeList = documentSignatures.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature"); XAdESValidation xadesValidation = new XAdESValidation(this.documentContext); for (int idx = 0; idx < signatureNodeList.getLength(); idx++) { Element signatureElement = (Element) signatureNodeList.item(idx); //LOG.debug("signatureValue: "+signatureElement.getTextContent()); xadesValidation.prepareDocument(signatureElement); KeyInfoKeySelector keySelector = new KeyInfoKeySelector(); DOMValidateContext domValidateContext = new DOMValidateContext(keySelector, signatureElement); ODFURIDereferencer dereferencer = new ODFURIDereferencer(document); domValidateContext.setURIDereferencer(dereferencer); XMLSignatureFactory xmlSignatureFactory = XMLSignatureFactory.getInstance(); XMLSignature xmlSignature = xmlSignatureFactory.unmarshalXMLSignature(domValidateContext); boolean valid = xmlSignature.validate(domValidateContext); if (!valid) { LOG.debug("invalid signature"); continue; } checkIntegrity(xmlSignature, document, originalDocument); X509Certificate signingCertificate = keySelector.getCertificate(); SignatureInfo signatureInfo = xadesValidation.validate(documentSignatures, xmlSignature, signatureElement, signingCertificate); signatureInfos.add(signatureInfo); } return signatureInfos; } } return signatureInfos; }
From source file:ee.ria.DigiDoc.fragment.ContainerDataFilesFragment.java
private File extractAttachment(String fileName) { File attachment = null;//from w ww. java2 s. c o m File containerFile = containerFacade.getContainerFile(); try (ZipInputStream zis = new ZipInputStream(new FileInputStream(containerFile))) { ZipEntry ze; while ((ze = zis.getNextEntry()) != null) { if (fileName.equals(ze.getName())) { File cacheDir = FileUtils.getDataFilesCacheDirectory(getContext()); attachment = new File(cacheDir, fileName); try (FileOutputStream out = new FileOutputStream(attachment)) { IOUtils.copy(zis, out); } break; } } } catch (IOException e) { Timber.e(e, "Extracting attachment from container failed"); } return attachment; }