List of usage examples for java.util.zip ZipInputStream ZipInputStream
public ZipInputStream(InputStream in)
From source file:io.apicurio.hub.api.codegen.OpenApi2ThorntailTest.java
/** * Test method for {@link io.apicurio.hub.api.codegen.OpenApi2Thorntail#generate()}. *//* w w w . ja va 2s . co m*/ @Test public void testGenerateOnly() throws IOException { OpenApi2Thorntail generator = new OpenApi2Thorntail() { /** * @see io.apicurio.hub.api.codegen.OpenApi2Thorntail#processApiDoc() */ @Override protected String processApiDoc() { try { return IOUtils.toString(OpenApi2ThorntailTest.class.getClassLoader() .getResource("OpenApi2ThorntailTest/beer-api.codegen.json")); } catch (IOException e) { throw new RuntimeException(e); } } }; generator.setUpdateOnly(false); generator .setOpenApiDocument(getClass().getClassLoader().getResource("OpenApi2ThorntailTest/beer-api.json")); ByteArrayOutputStream outputStream = generator.generate(); //FileUtils.writeByteArrayToFile(new File("C:\\Users\\ewittman\\tmp\\output.zip"), outputStream.toByteArray()); // Validate the result try (ZipInputStream zipInputStream = new ZipInputStream( new ByteArrayInputStream(outputStream.toByteArray()))) { ZipEntry zipEntry = zipInputStream.getNextEntry(); while (zipEntry != null) { if (!zipEntry.isDirectory()) { String name = zipEntry.getName(); // System.out.println(name); Assert.assertNotNull(name); URL expectedFile = getClass().getClassLoader() .getResource(getClass().getSimpleName() + "/_expected/generated-api/" + name); Assert.assertNotNull("Could not find expected file for entry: " + name, expectedFile); String expected = IOUtils.toString(expectedFile); String actual = IOUtils.toString(zipInputStream); // System.out.println("-----"); // System.out.println(actual); // System.out.println("-----"); Assert.assertEquals("Expected vs. actual failed for entry: " + name, normalizeString(expected), normalizeString(actual)); } zipEntry = zipInputStream.getNextEntry(); } } }
From source file:JarResource.java
private List<String> load(InputStream is) throws IOException { List<String> jarContents = new ArrayList<String>(); try {// w ww.ja va 2 s . com ZipInputStream zis = new ZipInputStream(is); ZipEntry ze = zis.getNextEntry(); while (ze != null) { if (ze.isDirectory()) { continue; } jarContents.add(ze.getName()); ze = zis.getNextEntry(); } } catch (NullPointerException e) { System.out.println("done."); } return jarContents; }
From source file:de.knowwe.revisions.upload.UploadRevisionZip.java
@SuppressWarnings("unchecked") @Override//from ww w .j a v a 2s.c om public void execute(UserActionContext context) throws IOException { HashMap<String, String> pages = new HashMap<>(); List<FileItem> items = null; String zipname = null; try { items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(context.getRequest()); } catch (FileUploadException e) { throw new IOException("error during processing upload", e); } for (FileItem item : items) { zipname = item.getName(); InputStream filecontent = item.getInputStream(); ZipInputStream zin = new ZipInputStream(filecontent); ZipEntry ze; while ((ze = zin.getNextEntry()) != null) { String name = ze.getName(); if (!name.contains("/")) { // this is an article String title = Strings.decodeURL(name); title = title.substring(0, title.length() - 4); String content = IOUtils.toString(zin, "UTF-8"); zin.closeEntry(); pages.put(title, content); } else { // TODO: what to do here? // this is an attachment // String[] splittedName = name.split("/"); // String title = Strings.decodeURL(splittedName[0]); // String filename = Strings.decodeURL(splittedName[1]); // // System.out.println("Attachment: " + name); // String content = IOUtils.toString(zin, "UTF-8"); // Environment.getInstance().getWikiConnector().storeAttachment(title, // filename, // context.getUserName(), zin); zin.closeEntry(); } } zin.close(); filecontent.close(); } if (zipname != null) { UploadedRevision rev = new UploadedRevision(context.getWeb(), pages, zipname); RevisionManager.getRM(context).setUploadedRevision(rev); } context.sendRedirect("../Wiki.jsp?page=" + context.getTitle()); }
From source file:be.fedict.eid.applet.service.signer.odf.ODFSignatureVerifier.java
/** * return list of signers for the document available via the given * URL./*from w w w . j a v a2 s . c o m*/ * * @param odfUrl * @return list of X509 certificates * @throws IOException * @throws ParserConfigurationException * @throws SAXException * @throws MarshalException * @throws XMLSignatureException */ public static List<X509Certificate> getSigners(URL odfUrl) throws IOException, ParserConfigurationException, SAXException, MarshalException, XMLSignatureException { List<X509Certificate> signers = new LinkedList<X509Certificate>(); if (null == odfUrl) { throw new IllegalArgumentException("odfUrl is null"); } ZipInputStream odfZipInputStream = new ZipInputStream(odfUrl.openStream()); ZipEntry zipEntry; while (null != (zipEntry = odfZipInputStream.getNextEntry())) { if (ODFUtil.isSignatureFile(zipEntry)) { Document documentSignatures = ODFUtil.loadDocument(odfZipInputStream); NodeList signatureNodeList = documentSignatures.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature"); for (int idx = 0; idx < signatureNodeList.getLength(); idx++) { Node signatureNode = signatureNodeList.item(idx); X509Certificate signer = getVerifiedSignatureSigner(odfUrl, signatureNode); if (null == signer) { LOG.debug("JSR105 says invalid signature"); } else { signers.add(signer); } } return signers; } } LOG.debug("no signature file present"); return signers; }
From source file:com.joliciel.talismane.machineLearning.ExternalResourceFinderImpl.java
@Override public void addExternalResources(File externalResourceFile) { try {/*from w w w. j a v a 2 s .c o m*/ if (externalResourceFile.isDirectory()) { File[] files = externalResourceFile.listFiles(); for (File resourceFile : files) { LOG.debug("Reading " + resourceFile.getName()); if (resourceFile.getName().endsWith(".zip")) { ZipInputStream zis = new ZipInputStream(new FileInputStream(resourceFile)); zis.getNextEntry(); ObjectInputStream ois = new ObjectInputStream(zis); ExternalResource<?> externalResource = (ExternalResource<?>) ois.readObject(); this.addExternalResource(externalResource); } else { TextFileResource textFileResource = new TextFileResource(resourceFile); this.addExternalResource(textFileResource); } } } else { LOG.debug("Reading " + externalResourceFile.getName()); if (externalResourceFile.getName().endsWith(".zip")) { ZipInputStream zis = new ZipInputStream(new FileInputStream(externalResourceFile)); zis.getNextEntry(); ObjectInputStream ois = new ObjectInputStream(zis); ExternalResource<?> externalResource = (ExternalResource<?>) ois.readObject(); this.addExternalResource(externalResource); } else { TextFileResource textFileResource = new TextFileResource(externalResourceFile); this.addExternalResource(textFileResource); } } } catch (IOException e) { LogUtils.logError(LOG, e); throw new RuntimeException(e); } catch (ClassNotFoundException e) { LogUtils.logError(LOG, e); throw new RuntimeException(e); } }
From source file:de.micromata.genome.db.jpa.genomecore.chronos.JobStoreTest.java
License:asdf
public void findClassPathInJars() { try {/* www.j a v a 2 s . c o m*/ Iterator it = FileUtils.iterateFiles(new File("."), new String[] { "jar" }, true); for (; it.hasNext();) { File f = (File) it.next(); ZipInputStream zf = new ZipInputStream(new FileInputStream(f)); ZipEntry ze; while ((ze = zf.getNextEntry()) != null) { String name = ze.getName(); if (name.startsWith("org/objectweb/asm") == true) { System.out.println("Found: " + f.getCanonicalPath()); zf.closeEntry(); break; } zf.closeEntry(); } zf.close(); } } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:org.businessmanager.geodb.OpenGeoDBImpl.java
private void init() { InputStream rs = getClass().getClassLoader().getResourceAsStream("geodb.zip"); ZipInputStream zipInputStream = new ZipInputStream(rs); ZipEntry ze;//from ww w .j ava 2 s .c o m try { BufferedReader reader = new BufferedReader(new InputStreamReader(zipInputStream, "UTF-8")); while ((ze = zipInputStream.getNextEntry()) != null) { String lname = ze.getName().substring(0, ze.getName().lastIndexOf(".tab")).toLowerCase(); String line; OpenGeoDBMapper mapper = new OpenGeoDBMapper(); while ((line = reader.readLine()) != null) { if (line.length() > 0) { if (line.startsWith("#")) continue; OpenGeoEntry entry = OpenGeoEntry.fromCSVLine(line, "\t"); if (entry != null) { String[] plz = entry.getPlz(); for (String plzEntry : plz) { mapper.putZipCode(plzEntry.trim(), entry); } mapper.putAreaCode(entry.getVorwahl(), entry); } } } mappers.put(lname, mapper); } } catch (IOException e) { e.printStackTrace(); } }
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.// w w w . j a v a 2 s . c o m * * @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:edu.sabanciuniv.sentilab.sare.controllers.base.documentStore.NonDerivedStoreFactory.java
protected NonDerivedStoreFactory<T> addZipPacket(T store, InputStream input) throws IOException { Validate.notNull(store, CannedMessages.NULL_ARGUMENT, "store"); Validate.notNull(input, CannedMessages.NULL_ARGUMENT, "input"); ZipInputStream zipStream = new ZipInputStream(input); ZipEntry zipEntry;/* w ww . java 2 s.c o m*/ while ((zipEntry = zipStream.getNextEntry()) != null) { if (!zipEntry.isDirectory()) { // we create a byte stream so that the input stream is not closed by the underlying methods. this.createSpecific(store, new ByteArrayInputStream(IOUtils.toByteArray(zipStream)), FilenameUtils.getExtension(zipEntry.getName())); } } return this; }
From source file:com.gooddata.util.ZipHelperTest.java
private static void verifyZipContent(ByteArrayOutputStream zip, String shouldContain) throws Exception { try (ZipInputStream zipInputStream = new ZipInputStream(new ByteArrayInputStream(zip.toByteArray()))) { ZipEntry entry = zipInputStream.getNextEntry(); assertThat(entry, notNullValue()); assertThat(entry.getName(), is(shouldContain)); }//from www. j av a2 s . c om }