List of usage examples for java.util.zip ZipEntry getName
public String getName()
From source file:com.wavemaker.tools.project.upgrade.five_dot_zero.WebXmlUpgradeTask.java
@Override public void doUpgrade(Project project, UpgradeInfo upgradeInfo) { File webXml = project.getWebXmlFile(); if (webXml.exists()) { try {/*from w w w .jav a 2 s. c om*/ File webXmlBak = project.getWebInfFolder().getFile(WEB_XML_BACKUP); webXmlBak.getContent().write(webXml); webXml.delete(); File userWebXml = project.getWebInfFolder().getFile(ProjectConstants.USER_WEB_XML); InputStream resourceStream = this.getClass().getClassLoader() .getResourceAsStream(ProjectManager._TEMPLATE_APP_RESOURCE_NAME); ZipInputStream resourceZipStream = new ZipInputStream(resourceStream); ZipEntry zipEntry = null; while ((zipEntry = resourceZipStream.getNextEntry()) != null) { if ("webapproot/WEB-INF/user-web.xml".equals(zipEntry.getName())) { Writer writer = userWebXml.getContent().asWriter(); IOUtils.copy(resourceZipStream, writer); writer.close(); } } resourceZipStream.close(); resourceStream.close(); } catch (IOException e) { throw new WMRuntimeException(e); } upgradeInfo.addMessage("The web.xml file has changed. If you have custom" + "modifications, please copy them from " + WEB_XML_BACKUP + " to the new user-web.xml."); } }
From source file:com.josue.lottery.eap.service.core.LotoImporter.java
private void readZip(File file) { ZipFile zipFile = null;/*from w ww .jav a 2 s. c o m*/ try { logger.info("unzipping ************"); zipFile = new ZipFile(file); File dataDir = new File(System.getProperty("jboss.server.data.dir")); File dest = new File(dataDir, "deziped.htm"); Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (entry.getName().endsWith(".HTM")) { InputStream stream = zipFile.getInputStream(entry); OutputStream oStr = null; try { oStr = new FileOutputStream(dest); IOUtils.copy(stream, oStr); parseHtml(dest); } catch (IOException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(oStr); } } } } catch (IOException ex) { logger.error(ex); } finally { try { zipFile.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:net.sourceforge.jweb.maven.mojo.PropertiesOverideMojo.java
private boolean acceptMime(ZipEntry entry) { for (String ext : extensionSet) { if (entry.getName().endsWith(ext)) { return true; }/* www . ja va 2 s. c om*/ } return false; }
From source file:asciidoc.maven.plugin.AbstractAsciiDocMojo.java
private void unzipEntry(ZipFile zipfile, ZipEntry zipEntry, File outputDir) throws IOException { if (zipEntry.isDirectory()) { createDir(new File(outputDir, zipEntry.getName())); return;//w w w . j a v a2 s. c om } File outputFile = new File(outputDir, zipEntry.getName()); if (!outputFile.getParentFile().exists()) { createDir(outputFile.getParentFile()); } if (getLog().isDebugEnabled()) getLog().debug("Extracting " + zipEntry); BufferedInputStream inputStream = new BufferedInputStream(zipfile.getInputStream(zipEntry)); BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile)); try { IOUtils.copy(inputStream, outputStream); } finally { outputStream.close(); inputStream.close(); } }
From source file:com.flexive.tests.disttools.DistPackageTest.java
private String getTempPath(File tempDir, ZipEntry zipEntry) { return tempDir.getPath() + File.separator + zipEntry.getName(); }
From source file:io.wcm.devops.conga.tooling.maven.plugin.GenerateMojo.java
/** * Checks if the JAR file of the given dependency has a CONGA-INF/ directory. * @param dependency Dependency/*from ww w . j a v a2 s .c om*/ * @return true if configuration definitions found */ private boolean hasCongaDefinitions(Dependency dependency) { if (!StringUtils.equals(dependency.getType(), "jar")) { return false; } String fileInfo = dependency.toString(); try { Artifact artifact = getArtifact(dependency); fileInfo = FileUtil.getCanonicalPath(artifact.getFile()); try (ZipFile zipFile = new ZipFile(artifact.getFile())) { Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (StringUtils.startsWith(entry.getName(), BuildConstants.CLASSPATH_PREFIX)) { return true; } } } } catch (IOException ex) { throw new GeneratorException("Unable to read from JAR file: " + fileInfo, ex); } return false; }
From source file:JarResource.java
private List<String> load(InputStream is) throws IOException { List<String> jarContents = new ArrayList<String>(); try {/*from w w w. j av a2 s . c o m*/ 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:com.genericworkflownodes.knime.nodes.io.outputfile.OutputFileNodeModel.java
/** * {@inheritDoc}/* w w w .jav a 2s. com*/ */ @Override protected void loadInternals(final File internDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException { ZipFile zip = new ZipFile(new File(internDir, "loadeddata")); @SuppressWarnings("unchecked") Enumeration<ZipEntry> entries = (Enumeration<ZipEntry>) zip.entries(); int BUFFSIZE = 2048; byte[] BUFFER = new byte[BUFFSIZE]; while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (entry.getName().equals("rawdata.bin")) { int size = (int) entry.getSize(); byte[] data = new byte[size]; InputStream in = zip.getInputStream(entry); int len; int totlen = 0; while ((len = in.read(BUFFER, 0, BUFFSIZE)) >= 0) { System.arraycopy(BUFFER, 0, data, totlen, len); totlen += len; } this.data = new String(data); } } zip.close(); }
From source file:net.osten.watermap.batch.FetchPCTWaypointsJob.java
private void unZipIt(File zipFile, File outputFolder) { byte[] buffer = new byte[1024]; try (ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile))) { // get the zipped file list entry ZipEntry ze = zis.getNextEntry(); while (ze != null) { String fileName = ze.getName(); File newFile = new File(outputFolder.getAbsolutePath() + File.separator + fileName); log.log(Level.FINER, "file unzip : {0}", new Object[] { newFile.getAbsoluteFile() }); // create all non existing folders else you will hit FileNotFoundException for compressed folder new File(newFile.getParent()).mkdirs(); try (FileOutputStream fos = new FileOutputStream(newFile)) { int len; while ((len = zis.read(buffer)) > 0) { fos.write(buffer, 0, len); }/*from w ww . ja v a 2 s . c o m*/ } ze = zis.getNextEntry(); // move newFile to data directory try { // have to delete first since FileUtils does not overwrite File destinationFile = new File(outputFolder + File.separator + newFile.getName()); if (destinationFile.exists()) { destinationFile.delete(); } FileUtils.moveFileToDirectory(newFile, outputFolder, false); } catch (FileExistsException ioe) { log.warning(ioe.getLocalizedMessage()); } catch (IOException ioe) { log.warning(ioe.getLocalizedMessage()); } } // close the last entry zis.closeEntry(); } catch (IOException e) { log.warning(e.getLocalizedMessage()); } }
From source file:com.samczsun.helios.LoadedFile.java
public void reset() throws IOException { files.clear();/* w w w . j a v a2 s .co m*/ classes.clear(); ZipFile zipFile = null; try { zipFile = new ZipFile(file); Enumeration<? extends ZipEntry> enumeration = zipFile.entries(); while (enumeration.hasMoreElements()) { ZipEntry zipEntry = enumeration.nextElement(); if (!zipEntry.isDirectory()) { load(zipEntry.getName(), zipFile.getInputStream(zipEntry)); } } } catch (ZipException e) { //Probably not a ZIP file FileInputStream inputStream = null; try { inputStream = new FileInputStream(file); load(this.name, inputStream); } finally { if (inputStream != null) { inputStream.close(); } } } finally { if (zipFile != null) { try { zipFile.close(); } catch (IOException e) { } } } }