List of usage examples for java.util.zip ZipEntry getName
public String getName()
From source file:io.github.tsabirgaliev.ZipperInputStreamTest.java
public void testJDKCompatibility() throws IOException { ZipperInputStream lzis = new ZipperInputStream(enumerate(file1, file2)); ZipInputStream zis = new ZipInputStream(lzis); {/* ww w . j a v a 2 s . c o m*/ ZipEntry entry1 = zis.getNextEntry(); assert file1.getPath().equals(entry1.getName()); assert IOUtils.contentEquals(zis, file1.getStream()); zis.closeEntry(); } { ZipEntry entry2 = zis.getNextEntry(); assert file2.getPath().equals(entry2.getName()); assert IOUtils.contentEquals(zis, file2.getStream()); zis.closeEntry(); } }
From source file:com.opengamma.util.db.script.ZipFileDbScript.java
@Override public String getScript() throws IOException { ZipInputStream zippedIn = null; try {// w w w. j a v a2 s . com zippedIn = new ZipInputStream(new FileInputStream(getZipFile())); ZipEntry entry; while ((entry = zippedIn.getNextEntry()) != null) { if (entry.getName().equals(getEntryName())) { break; } } if (entry == null) { throw new OpenGammaRuntimeException( "No entry found in zip file " + getZipFile() + " with name " + getEntryName()); } return IOUtils.toString(zippedIn); } catch (FileNotFoundException e) { throw new OpenGammaRuntimeException("Zip file not found: " + getZipFile()); } catch (IOException e) { throw new OpenGammaRuntimeException("Error reading from zip file: " + getZipFile()); } finally { if (zippedIn != null) { try { zippedIn.close(); } catch (IOException e) { } } } }
From source file:com.cisco.surf.jenkins.plugins.jenkow.test.eclipse.UpdateSiteTest.java
public void testUpdateSite() throws Exception { URL u = new URL(getURL(), "plugin/" + PLUGIN_NAME + "/eclipse.site/content.jar"); Set<String> names = new HashSet<String>(); JarInputStream jis = new JarInputStream(u.openStream()); try {/* w w w . j a v a 2 s.c om*/ while (true) { ZipEntry ze = jis.getNextEntry(); if (ze == null) break; names.add(ze.getName()); } } finally { IOUtils.closeQuietly(jis); } assertTrue(names.contains("content.xml")); }
From source file:com.cisco.step.jenkins.plugins.jenkow.test.eclipse.UpdateSiteTest.java
public void testUpdateSite() throws Exception { URL u = new URL(getURL(), "plugin/" + Consts.PLUGIN_NAME + "/eclipse.site/content.jar"); Set<String> names = new HashSet<String>(); JarInputStream jis = new JarInputStream(u.openStream()); try {/*from ww w .ja va2 s. c o m*/ while (true) { ZipEntry ze = jis.getNextEntry(); if (ze == null) break; names.add(ze.getName()); } } finally { IOUtils.closeQuietly(jis); } assertTrue(names.contains("content.xml")); }
From source file:be.fedict.eid.dss.document.zip.ZIPSignatureOutputStream.java
@Override public void close() throws IOException { super.close(); byte[] signatureData = toByteArray(); /*/* w w w . j ava 2 s . c o m*/ * Copy the original ZIP content. */ ZipOutputStream zipOutputStream = new ZipOutputStream(this.targetOutputStream); ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(this.originalZipFile)); ZipEntry zipEntry; while (null != (zipEntry = zipInputStream.getNextEntry())) { if (!zipEntry.getName().equals(ODFUtil.SIGNATURE_FILE)) { ZipEntry newZipEntry = new ZipEntry(zipEntry.getName()); zipOutputStream.putNextEntry(newZipEntry); LOG.debug("copying " + zipEntry.getName()); IOUtils.copy(zipInputStream, zipOutputStream); } } zipInputStream.close(); /* * Add the XML signature file to the ZIP package. */ zipEntry = new ZipEntry(ODFUtil.SIGNATURE_FILE); LOG.debug("writing " + zipEntry.getName()); zipOutputStream.putNextEntry(zipEntry); IOUtils.write(signatureData, zipOutputStream); zipOutputStream.close(); }
From source file:be.fedict.eid.dss.document.zip.ZIPResourceResolver.java
private InputStream findZIPEntry(Attr dsReferenceUri) throws IOException { String entryName = dsReferenceUri.getValue(); ZipInputStream zipInputStream = new ZipInputStream(new ByteArrayInputStream(this.document)); ZipEntry zipEntry; while (null != (zipEntry = zipInputStream.getNextEntry())) { if (entryName.equals(zipEntry.getName())) { return zipInputStream; }/*from w w w . j a v a2 s . co m*/ } return null; }
From source file:org.commonjava.indy.diags.ftest.DownloadDiagBundleTest.java
@Test @Ignore/*w ww .j ava2s . c o m*/ public void run() throws IndyClientException, IOException { boolean foundThreadDump = false; int logCount = 0; try (ZipInputStream in = module.getDiagnosticBundle()) { ZipEntry entry = null; while ((entry = in.getNextEntry()) != null) { if (entry.getName().equals(DiagnosticsManager.THREAD_DUMP_FILE)) { logger.debug("\n\nGot thread dump:\n\n{}\n\n", IOUtils.toString(in)); foundThreadDump = true; } else if (entry.getName().startsWith(DiagnosticsManager.LOGS_DIR + "/")) { logger.debug("\n\nGot log file: '{}'\n\n", entry.getName()); logCount++; } else { logger.debug("\n\nGot unknown file: '{}'\n\n", entry.getName()); } } } assertThat("Didn't find thread dump!", foundThreadDump, equalTo(true)); assertThat("Didn't find any logs!", logCount > 0, equalTo(true)); }
From source file:com.glue.feed.toulouse.open.data.venue.ToulouseEquipementsJob.java
@Override public void execute(JobExecutionContext arg0) throws JobExecutionException { try {//from www . j a v a 2s.c om URL url = new URL( "http://data.grandtoulouse.fr/web/guest/les-donnees/-/opendata/card/23851-equipements-culturels/resource/document?p_p_state=exclusive&_5_WAR_opendataportlet_jspPage=%2Fsearch%2Fview_card_license.jsp"); ZipInputStream zin = new ZipInputStream(url.openStream()); ZipEntry entry = GlueIOUtils.getEntry(zin, new FileExtensionFilter(".csv")); InputStream in = GlueIOUtils.getDeferredInputStream(zin, entry.getName()); BufferedReader reader = new BufferedReader( new InputStreamReader(new BOMInputStream(in), Charset.forName("UTF-8"))); CSVFeedParser<VenueBean> parser = new CSVFeedParser<>(reader, VenueBean.class); final FeedMessageListener<Venue> delegate = new VenueMessageListener(); final GlueObjectBuilder<VenueBean, Venue> venueBuilder = new VenueBeanVenueBuilder(); parser.setFeedMessageListener(new FeedMessageListener<VenueBean>() { @Override public void newMessage(VenueBean msg) throws Exception { Venue venue = venueBuilder.build(msg); delegate.newMessage(venue); } @Override public void close() throws IOException { delegate.close(); } }); parser.read(); parser.close(); LOG.info("Done"); } catch (Exception e) { LOG.error(e.getMessage(), e); throw new JobExecutionException(e); } }
From source file:com.agilejava.maven.docbkx.ZipFileProcessorTest.java
/** * DOCUMENT ME!/*from w w w . j a v a2 s . c o m*/ * * @throws Exception DOCUMENT ME! */ public void testProcessFile() throws Exception { File file = new File(getDirectory(), "sample.zip"); ZipFileProcessor processor = new ZipFileProcessor(file); final int[] count = new int[1]; processor.process(new ZipEntryVisitor() { public void visit(ZipEntry entry, InputStream in) throws IOException { count[0]++; assertTrue(FILENAMES.contains(entry.getName())); if ((entry.getCompressedSize() > 0) && entry.getName().endsWith("test2.txt")) { assertEquals("i have a dream", IOUtils.toString(in)); in.close(); } } }); assertEquals(3, count[0]); }
From source file:de.tudarmstadt.ukp.clarin.webanno.project.page.ImportUtil.java
/** * copy Project META_INF from the exported project * @param zip the ZIP file./*w w w .j a v a 2 s. c o m*/ * @param aProject the project. * @param aRepository the repository service. * @throws IOException if an I/O error occurs. */ @SuppressWarnings("rawtypes") public static void createProjectMetaInf(ZipFile zip, Project aProject, RepositoryService aRepository) throws IOException { for (Enumeration zipEnumerate = zip.entries(); zipEnumerate.hasMoreElements();) { ZipEntry entry = (ZipEntry) zipEnumerate.nextElement(); // Strip leading "/" that we had in ZIP files prior to 2.0.8 (bug #985) String entryName = normalizeEntryName(entry); if (entryName.startsWith(META_INF)) { File metaInfDir = new File(aRepository.getMetaInfFolder(aProject), FilenameUtils.getPath(entry.getName().replace(META_INF, ""))); // where the file reside in the META-INF/... directory FileUtils.forceMkdir(metaInfDir); FileUtils.copyInputStreamToFile(zip.getInputStream(entry), new File(metaInfDir, FilenameUtils.getName(entry.getName()))); LOG.info("Imported META-INF for project [" + aProject.getName() + "] with id [" + aProject.getId() + "]"); } } }