List of usage examples for java.util.zip ZipInputStream getNextEntry
public ZipEntry getNextEntry() throws IOException
From source file:cpcc.vvrte.services.db.DownloadServiceTest.java
public void shouldListContent() throws IOException { byte[] actual = sut.getAllVirtualVehicles(); FileUtils.writeByteArrayToFile(new File("target/lala.zip"), actual); ByteArrayInputStream bis = new ByteArrayInputStream(actual); ZipInputStream zis = new ZipInputStream(bis, Charset.forName("UTF-8")); for (ZipEntry entry = zis.getNextEntry(); entry != null; entry = zis.getNextEntry()) { System.out.printf("%s %5d %5d %s %s\n", entry.isDirectory() ? "d" : "-", entry.getSize(), entry.getCompressedSize(), sdf.format(entry.getTime()), entry.getName()); // byte[] data = IOUtils.toByteArray(zis); // System.out.write(data); // System.out.println(); }/*from www . j a v a 2 s. co m*/ }
From source file:com.yahoo.storm.yarn.TestConfig.java
private void unzipFile(String filePath) { FileInputStream fis = null;// ww w .j a v a 2s .c o m ZipInputStream zipIs = null; ZipEntry zEntry = null; try { fis = new FileInputStream(filePath); zipIs = new ZipInputStream(new BufferedInputStream(fis)); while ((zEntry = zipIs.getNextEntry()) != null) { try { byte[] tmp = new byte[4 * 1024]; FileOutputStream fos = null; String opFilePath = "lib/" + zEntry.getName(); if (zEntry.isDirectory()) { LOG.debug("Create a folder " + opFilePath); if (zEntry.getName().indexOf(Path.SEPARATOR) == (zEntry.getName().length() - 1)) storm_home = opFilePath.substring(0, opFilePath.length() - 1); new File(opFilePath).mkdir(); } else { LOG.debug("Extracting file to " + opFilePath); fos = new FileOutputStream(opFilePath); int size = 0; while ((size = zipIs.read(tmp)) != -1) { fos.write(tmp, 0, size); } fos.flush(); fos.close(); } } catch (Exception ex) { ex.printStackTrace(); } } zipIs.close(); } catch (FileNotFoundException e) { LOG.warn(e.toString()); } catch (IOException e) { LOG.warn(e.toString()); } LOG.info("storm_home: " + storm_home); }
From source file:com.carolinarollergirls.scoreboard.jetty.MediaServlet.java
protected void processZipFileItem(FileItemFactory factory, FileItem zip, List<FileItem> fileItems) throws IOException { ZipInputStream ziS = new ZipInputStream(zip.getInputStream()); ZipEntry zE;/*from w w w .ja va 2 s.com*/ try { while (null != (zE = ziS.getNextEntry())) { if (zE.isDirectory() || !uploadFileNameFilter.accept(null, zE.getName())) continue; FileItem item = factory.createItem(null, null, false, zE.getName()); OutputStream oS = item.getOutputStream(); IOUtils.copyLarge(ziS, oS); oS.close(); fileItems.add(item); } } finally { ziS.close(); } }
From source file:com.gnadenheimer.mg3.controller.admin.AdminConfigController.java
@FXML private void cmdUpdateSET(ActionEvent event) { Task taskUpdateSET = new Task<Void>() { @Override//w w w. j a v a 2s . c o m public Void call() { try { EntityManager entityManager = Utils.getInstance().getEntityManagerFactory() .createEntityManager(); entityManager.getTransaction().begin(); String temp = ""; Integer count = 0; entityManager.createQuery("delete from TblContribuyentes t").executeUpdate(); for (Integer i = 0; i <= 9; i++) { URL url = new URL( "http://www.set.gov.py/rest/contents/download/collaboration/sites/PARAGUAY-SET/documents/informes-periodicos/ruc/ruc" + String.valueOf(i) + ".zip"); ZipInputStream zipStream = new ZipInputStream(url.openStream(), StandardCharsets.UTF_8); zipStream.getNextEntry(); Scanner sc = new Scanner(zipStream, "UTF-8"); while (sc.hasNextLine()) { String[] ruc = sc.nextLine().split("\\|"); temp = ruc[0] + " - " + ruc[1] + " - " + ruc[2]; if (ruc[0].length() > 0 && ruc[1].length() > 0 && ruc[2].length() == 1) { TblContribuyentes c = new TblContribuyentes(); c.setRucSinDv(ruc[0]); c.setRazonSocial(StringEscapeUtils.escapeSql(ruc[1])); c.setDv(ruc[2]); entityManager.persist(c); updateMessage("Descargando listado de RUC con terminacion " + String.valueOf(i) + " - Cantidad de contribuyentes procesada: " + String.format("%,d", count) + " de aprox. 850.000."); count++; } else { updateMessage(temp); } } entityManager.getTransaction().commit(); entityManager.getTransaction().begin(); } updateMessage("Lista de RUC actualizada..."); return null; } catch (Exception ex) { App.showException(this.getClass().getName(), ex.getMessage(), ex); } return null; } }; lblUpdateSET.textProperty().bind(taskUpdateSET.messageProperty()); new Thread(taskUpdateSET).start(); }
From source file:com.jkoolcloud.tnt4j.streams.inputs.ZipLineStream.java
private boolean hasNextEntry() throws IOException { if (zipStream instanceof ZipInputStream) { ZipInputStream zis = (ZipInputStream) zipStream; ZipEntry entry;/*from ww w. j ava 2 s . c om*/ while ((entry = zis.getNextEntry()) != null) { String entryName = entry.getName(); if (entry.getSize() != 0 && (zipEntriesMask == null || entryName.matches(zipEntriesMask))) { totalBytesCount += entry.getSize(); lineReader = new LineNumberReader(new BufferedReader(new InputStreamReader(zis))); lineNumber = 0; logger().log(OpLevel.DEBUG, StreamsResources.getString(StreamsResources.RESOURCE_BUNDLE_NAME, "ZipLineStream.opening.entry"), entryName); return true; } } } return false; }
From source file:com.agilejava.maven.docbkx.ZipFileProcessor.java
/** * Processes the contents of the zip file by processing all zip file entries in sequence * and calling {@link ZipFileProcessor.ZipEntryVisitor#visit(ZipEntry, InputStream)} for every * zip file entry encountered./*www .j a v a 2s. c om*/ * * @param visitor The visitor receiving the events. * * @throws IOException If it turned out to be impossible to read entries from the zip file passed * in. */ public void process(ZipEntryVisitor visitor) throws IOException { InputStream in = null; ZipInputStream zipIn = null; try { in = new FileInputStream(file); in = new BufferedInputStream(in); zipIn = new ZipInputStream(in); ZipEntry entry = null; while ((entry = zipIn.getNextEntry()) != null) { visitor.visit(entry, new SafeZipEntryInputStream(entry, zipIn)); } } finally { IOUtils.closeQuietly(zipIn); IOUtils.closeQuietly(in); } }
From source file:org.statmantis.mport.retro.event.RetrosheetEventReader.java
@Override protected EventInformation read(InputStream stream) throws IOException { ZipInputStream zis = new ZipInputStream(stream); try {//from w ww . j a v a 2s .c o m EventInformation info = new EventInformation(); ZipEntry entry = zis.getNextEntry(); while (entry != null) { try { BufferedReader reader = new BufferedReader(new InputStreamReader(zis)); if (entry.getName().equals("TEAM" + year)) { readTeamFile(entry.getName(), reader, info); } else if (entry.getName().endsWith(".ROS")) { readRosterFile(entry.getName(), reader, info); } else if (entry.getName().endsWith(".EVA") || entry.getName().endsWith(".EVN") || entry.getName().endsWith(".eba") || entry.getName().endsWith(".ebn")) { readEventFile(entry.getName(), reader, info); } else { throw new RetrosheetRuntimeException("Unknown zip entry: " + entry); } } catch (Exception e) { throw new RetrosheetRuntimeException("Error reading zip entry " + entry.getName(), e); } entry = zis.getNextEntry(); } return info; } finally { try { zis.close(); } catch (Exception e) { //no-op } } }
From source file:br.eti.ranieri.opcoesweb.importacao.offline.ImportadorOffline.java
public void importar(URL url, ConfiguracaoImportacao configuracaoImportacao) throws Exception { HttpURLConnection connection = (HttpURLConnection) url.openConnection(); if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) { throw new Exception("Requisio HTTP retornou cdigo de erro: " + connection.getResponseCode()); }/*www .ja v a2s .c o m*/ List<CotacaoBDI> cotacoes = null; ZipInputStream zip = null; try { zip = new ZipInputStream(connection.getInputStream()); ZipEntry entry; while ((entry = zip.getNextEntry()) != null) { if ("BDIN".equals(entry.getName())) { cotacoes = parser.parseBDI(zip); zip.closeEntry(); break; } else if (entry.getName().startsWith("COTAHIST_") && entry.getName().endsWith(".TXT")) { cotacoes = parser.parseHistorico(zip); zip.closeEntry(); break; } } zip.close(); } catch (ZipException e) { log.error("Formato invalido de arquivo zip", e); } catch (IOException e) { log.error("Erro de leitura do arquivo zip", e); } finally { if (zip != null) IOUtils.closeQuietly(zip); } calcularBlackScholes(cotacoes, configuracaoImportacao); }
From source file:io.lightlink.excel.StreamingExcelTransformer.java
public void doExport(InputStream template, OutputStream out, ExcelStreamVisitor visitor) throws IOException { try {/*w w w. ja v a 2 s . co m*/ ZipInputStream zipIn = new ZipInputStream(template); ZipOutputStream zipOut = new ZipOutputStream(out); ZipEntry entry; Map<String, byte[]> sheets = new HashMap<String, byte[]>(); while ((entry = zipIn.getNextEntry()) != null) { String name = entry.getName(); if (name.startsWith("xl/sharedStrings.xml")) { byte[] bytes = IOUtils.toByteArray(zipIn); zipOut.putNextEntry(new ZipEntry(name)); zipOut.write(bytes); sharedStrings = processSharedStrings(bytes); } else if (name.startsWith("xl/worksheets/sheet")) { byte[] bytes = IOUtils.toByteArray(zipIn); sheets.put(name, bytes); } else if (name.equals("xl/calcChain.xml")) { // skip this file, let excel recreate it } else if (name.equals("xl/workbook.xml")) { zipOut.putNextEntry(new ZipEntry(name)); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser saxParser = factory.newSAXParser(); Writer writer = new OutputStreamWriter(zipOut, "UTF-8"); byte[] bytes = IOUtils.toByteArray(zipIn); saxParser.parse(new ByteArrayInputStream(bytes), new WorkbookTemplateHandler(writer)); writer.flush(); } else { zipOut.putNextEntry(new ZipEntry(name)); IOUtils.copy(zipIn, zipOut); } } for (Map.Entry<String, byte[]> sheetEntry : sheets.entrySet()) { String name = sheetEntry.getKey(); byte[] bytes = sheetEntry.getValue(); zipOut.putNextEntry(new ZipEntry(name)); processSheet(bytes, zipOut, visitor); } zipIn.close(); template.close(); zipOut.close(); out.close(); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e.toString(), e); } }
From source file:be.fedict.eid.dss.document.asic.ASiCDSSDocumentService.java
@Override public List<SignatureInfo> verifySignatures(byte[] document, byte[] originalDocument) throws Exception { if (null != originalDocument) { throw new IllegalArgumentException("cannot perform original document verifications"); }/*from w ww. j a v a 2 s . com*/ ZipInputStream zipInputStream = new ZipInputStream(new ByteArrayInputStream(document)); ZipEntry zipEntry; while (null != (zipEntry = zipInputStream.getNextEntry())) { if (ASiCUtil.isSignatureZipEntry(zipEntry)) { break; } } List<SignatureInfo> signatureInfos = new LinkedList<SignatureInfo>(); if (null == zipEntry) { return signatureInfos; } XAdESValidation xadesValidation = new XAdESValidation(this.documentContext); Document documentSignaturesDocument = ODFUtil.loadDocument(zipInputStream); NodeList signatureNodeList = documentSignaturesDocument.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature"); for (int idx = 0; idx < signatureNodeList.getLength(); idx++) { Element signatureElement = (Element) signatureNodeList.item(idx); xadesValidation.prepareDocument(signatureElement); KeyInfoKeySelector keySelector = new KeyInfoKeySelector(); DOMValidateContext domValidateContext = new DOMValidateContext(keySelector, signatureElement); ASiCURIDereferencer dereferencer = new ASiCURIDereferencer(document); domValidateContext.setURIDereferencer(dereferencer); XMLSignatureFactory xmlSignatureFactory = XMLSignatureFactory.getInstance(); XMLSignature xmlSignature = xmlSignatureFactory.unmarshalXMLSignature(domValidateContext); boolean valid = xmlSignature.validate(domValidateContext); if (!valid) { continue; } // check whether all files have been signed properly SignedInfo signedInfo = xmlSignature.getSignedInfo(); @SuppressWarnings("unchecked") List<Reference> references = signedInfo.getReferences(); Set<String> referenceUris = new HashSet<String>(); for (Reference reference : references) { String referenceUri = reference.getURI(); referenceUris.add(URLDecoder.decode(referenceUri, "UTF-8")); } zipInputStream = new ZipInputStream(new ByteArrayInputStream(document)); while (null != (zipEntry = zipInputStream.getNextEntry())) { if (ASiCUtil.isSignatureZipEntry(zipEntry)) { continue; } if (false == referenceUris.contains(zipEntry.getName())) { LOG.warn("no ds:Reference for ASiC entry: " + zipEntry.getName()); return signatureInfos; } } X509Certificate signer = keySelector.getCertificate(); SignatureInfo signatureInfo = xadesValidation.validate(documentSignaturesDocument, xmlSignature, signatureElement, signer); signatureInfos.add(signatureInfo); } return signatureInfos; }