List of usage examples for java.util.zip ZipFile getName
public String getName()
From source file:org.atombeat.xquery.functions.util.GetZipEntries.java
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException { try {/*from w w w. j a va2s . c o m*/ String path = args[0].getStringValue(); ZipFile zf = new ZipFile(path); log.debug(zf.getName()); log.debug(zf.size()); log.debug(zf.hashCode()); ZipEntry e; Enumeration<? extends ZipEntry> entries = zf.entries(); ValueSequence s = new ValueSequence(); for (int i = 0; entries.hasMoreElements(); i++) { log.debug(i); e = entries.nextElement(); log.debug(e.getName()); log.debug(e.getComment()); log.debug(e.isDirectory()); log.debug(e.getCompressedSize()); log.debug(e.getCrc()); log.debug(e.getMethod()); log.debug(e.getSize()); log.debug(e.getTime()); if (!e.isDirectory()) s.add(new StringValue(e.getName())); } return s; } catch (Exception e) { throw new XPathException("error processing zip file: " + e.getLocalizedMessage(), e); } }
From source file:edu.harvard.i2b2.PreProcessFhirSpec.java
public PreProcessFhirSpec() throws IOException, XQueryUtilException { logger.trace("hi"); ArrayList<String> resourceList = new ArrayList<String>(); resourceList.add("Patient".toLowerCase()); resourceList.add("Medication".toLowerCase()); resourceList.add("MedicationStatement".toLowerCase()); resourceList.add("Observation".toLowerCase()); ZipFile zipFile = new ZipFile(Utils.getFilePath("fhir-spec.zip"));// fhir-all-xsd.zip logger.trace("" + zipFile.getName()); Enumeration<? extends ZipEntry> entries = zipFile.entries(); for (String rName : resourceList) { String fName = "site/" + rName + ".profile.xml"; logger.trace("" + zipFile.getEntry(fName)); String fContent = IOUtils.toString(zipFile.getInputStream(zipFile.getEntry(fName))); logger.trace("" + XQueryUtil.processXQuery( "declare default element namespace \"http://hl7.org/fhir\";//searchParam", fContent)); }// ww w . ja v a 2 s .c o m /*while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if(!entry.getName().matches(".*\\.html$")) continue; Pattern p = Pattern.compile("^site/([^\\.\\\\]*)\\..*$"); Matcher m = p.matcher(entry.getName()); String rname=""; if (m.matches()) { //logger.trace("" + entry.getName() + "->" + m.group(1)); rname=m.group(1).toLowerCase(); } if (resourceList.contains(rname)) logger.trace(entry.getName()+"->" + rname); // InputStream stream = zipFile.getInputStream(entry); }*/ }
From source file:com.l2jfree.gameserver.script.ScriptPackage.java
public ScriptPackage(ZipFile pack) { _scriptFiles = new FastList<ScriptDocument>(); _name = pack.getName(); addFiles(pack); }
From source file:com.opengamma.util.ZipUtils.java
/** * Unzips a ZIP archive./* w w w.ja v a2s .c om*/ * * @param zipFile the archive file, not null * @param outputDir the output directory, not null */ public static void unzipArchive(final ZipFile zipFile, final File outputDir) { ArgumentChecker.notNull(zipFile, "zipFile"); ArgumentChecker.notNull(outputDir, "outputDir"); try { Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (entry.isDirectory()) { FileUtils.forceMkdir(new File(outputDir, entry.getName())); continue; } File entryDestination = new File(outputDir, entry.getName()); entryDestination.getParentFile().mkdirs(); InputStream in = zipFile.getInputStream(entry); OutputStream out = new FileOutputStream(entryDestination); IOUtils.copy(in, out); IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } zipFile.close(); } catch (IOException ex) { throw new OpenGammaRuntimeException( "Error while extracting file: " + zipFile.getName() + " to: " + outputDir, ex); } }
From source file:org.jboss.windup.util.RecursiveZipMetaFactory.java
public ZipMetadata recursivelyExtract(ZipFile zip) { if (LOG.isDebugEnabled()) { LOG.debug(zip.getName() + ": " + this.startLocation.getAbsolutePath()); }//www . j a v a2 s . c om ZipMetadata archive = generateArchive(null, new File(zip.getName())); recursivelyExtract(archive, zip, this.startLocation); return archive; }
From source file:org.cloudfoundry.client.lib.archive.ZipApplicationArchive.java
/** * Create a new {@link ZipApplicationArchive} instance for the given <tt>zipFile</tt>. * @param zipFile The underling zip file *///from w ww.j a va2s .c o m public ZipApplicationArchive(ZipFile zipFile) { Assert.notNull(zipFile, "ZipFile must not be null"); this.zipFile = zipFile; this.entries = adaptZipEntries(zipFile); this.fileName = new File(zipFile.getName()).getName(); }
From source file:org.jboss.windup.util.RecursiveZipMetaFactory.java
protected void recursivelyExtract(ZipMetadata parent, ZipFile zip, File outputDirectory) { String fileName = StringUtils.substringAfterLast(zip.getName(), File.separator); File subOutputDir = new File(outputDirectory.getAbsolutePath() + File.separator + fileName); ZipEntry entry;//from w w w . j a v a 2 s . c om Enumeration<?> e = zip.entries(); while (e.hasMoreElements()) { entry = (ZipEntry) e.nextElement(); // must be a candidate file. if (!entry.isDirectory()) { if (archiveEndInEntryOfInterest(entry.getName())) { try { File extracted = unzipEntry(parent, entry, zip, subOutputDir); ZipFile zf = new ZipFile(extracted); // we should know it is a valid zip here.. ZipMetadata arch = generateArchive(parent, extracted); LOG.info("Prepared ZipMetadata: " + arch.getRelativePath()); recursivelyExtract(arch, zf, new File(StringUtils.substringBeforeLast(zf.getName(), File.separator))); } catch (FileNotFoundException e1) { LOG.warn("Skipping invalid zip entry: " + entry); } catch (IOException e1) { LOG.warn("Skipping invalid zip entry: " + entry); } } } } try { zip.close(); } catch (IOException e1) { LOG.error("Exception closing zip.", e1); } }
From source file:org.ambraproject.article.service.IngestArchiveProcessorTest.java
@Test(dataProvider = "sampleArticle", dataProviderClass = SampleArticleData.class) public void testProcessArticle(ZipFile archive, Article expectedArticle) throws Exception { Document articleXml = ingestArchiveProcessor.extractArticleXml(archive); Article result = ingestArchiveProcessor.processArticle(archive, articleXml); compareArticles(result, expectedArticle); String archiveName = archive.getName().contains(File.separator) ? archive.getName().substring(archive.getName().lastIndexOf(File.separator) + 1) : archive.getName();/* w w w . jav a 2 s .co m*/ assertEquals(result.getArchiveName(), archiveName, "Article didn't have archive name set correctly"); assertNotNull(result.getJournals(), "Returned article with null journal set"); assertEquals(result.getJournals().size(), 1, "Returned article with incorrect number of journals"); assertEquals(result.getJournals().iterator().next().geteIssn(), result.geteIssn(), "returned result with incorrect journal eIssn"); }
From source file:org.jboss.as.test.integration.jdr.mgmt.JdrReportManagmentTestCase.java
private void validateEntryNotEmpty(String fileName, ZipFile reportZip, String reportName) { String entryInZip = reportName + "/" + fileName; ZipEntry entry = reportZip.getEntry(entryInZip); Assert.assertNotNull("Report entry " + fileName + " missing from JDR report " + reportZip.getName(), entry); Assert.assertTrue("Report entry " + fileName + " was empty or could not be determined", entry.getSize() > 0);/*from ww w. j av a2s. c om*/ }
From source file:com.google.appinventor.buildserver.util.AARLibrary.java
/** * Extracts the package name from the Android Archive without needing to unzip it to a location * in the file system/*from w ww . jav a2s. c o m*/ * * @param zip the input stream reading from the Android Archive. * @return the package name declared in the archive's AndroidManifest.xml. * @throws IOException if reading the input stream fails. */ private String extractPackageName(ZipFile zip) throws IOException { ZipEntry entry = zip.getEntry("AndroidManifest.xml"); if (entry == null) { throw new IllegalArgumentException(zip.getName() + " does not contain AndroidManifest.xml"); } try { ZipEntryWrapper wrapper = new ZipEntryWrapper(zip.getInputStream(entry)); // the following call will automatically close the input stream opened above return AndroidManifest.getPackage(wrapper); } catch (StreamException | XPathExpressionException e) { throw new IOException("Exception processing AndroidManifest.xml", e); } }