List of usage examples for java.util.zip ZipEntry getName
public String getName()
From source file:com.gabrielluz.megasenaanalyzer.MegaSenaAnalyzer.java
public static byte[] unZipIt(InputStream is) throws IOException { byte[] buffer = new byte[1024]; ByteArrayOutputStream out = new ByteArrayOutputStream(); try (ZipInputStream zis = new ZipInputStream(is)) { ZipEntry ze = zis.getNextEntry(); while (ze != null) { if (ze.getName().compareToIgnoreCase("D_MEGA.HTM") == 0) { int len; while ((len = zis.read(buffer)) > 0) { out.write(buffer, 0, len); }/*www. j av a 2 s . c o m*/ } ze = zis.getNextEntry(); } zis.closeEntry(); } return out.toByteArray(); }
From source file:net.minecrell.quartz.launch.mappings.MappingsLoader.java
public static Mappings load(Logger logger) throws IOException { URI source;/* w w w. ja v a 2 s . c o m*/ try { source = requireNonNull(Mapping.class.getProtectionDomain().getCodeSource(), "Unable to find class source").getLocation().toURI(); } catch (URISyntaxException e) { throw new IOException("Failed to find class source", e); } Path location = Paths.get(source); logger.debug("Mappings location: {}", location); List<ClassNode> mappingClasses = new ArrayList<>(); // Load the classes from the source if (Files.isDirectory(location)) { // We're probably in development environment or something similar // Search for the class files Files.walkFileTree(location.resolve(PACKAGE), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (file.getFileName().toString().endsWith(".class")) { try (InputStream in = Files.newInputStream(file)) { ClassNode classNode = MappingsParser.loadClassStructure(in); mappingClasses.add(classNode); } } return FileVisitResult.CONTINUE; } }); } else { // Go through the JAR file try (ZipFile zip = new ZipFile(location.toFile())) { Enumeration<? extends ZipEntry> entries = zip.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); String name = StringUtils.removeStart(entry.getName(), MAPPINGS_DIR); if (entry.isDirectory() || !name.endsWith(".class") || !name.startsWith(PACKAGE_PREFIX)) { continue; } // Ok, we found something try (InputStream in = zip.getInputStream(entry)) { ClassNode classNode = MappingsParser.loadClassStructure(in); mappingClasses.add(classNode); } } } } return new Mappings(mappingClasses); }
From source file:eml.studio.server.file.FileUploadServlet.java
public static void unZipFiles(InputStream instream, String ID) throws IOException { ZipArchiveInputStream zin = new ZipArchiveInputStream(instream); java.util.zip.ZipEntry entry = null; while ((entry = zin.getNextZipEntry()) != null) { String zipEntryName = entry.getName(); String outPath = zipEntryName.replaceAll("\\*", "/"); String path = "lib"; path += zipEntryName.substring(zipEntryName.indexOf('/'), zipEntryName.length()); System.out.println("[path ]:" + path); if (!outPath.endsWith("/")) { InputStream in = zin; HDFSIO.uploadModel("/" + ID + "/" + path, in); }//w w w .j a v a2s. co m } zin.close(); }
From source file:Main.java
public static File UpdateZipFromPath(String sZipFile, String sPath) throws Exception { File tmpFile = File.createTempFile("z4zip-tmp-", ".zip"); tmpFile.deleteOnExit();/*w ww.jav a2 s . co m*/ ZipFile inZip = new ZipFile(sZipFile); ZipOutputStream outZip = new ZipOutputStream(new FileOutputStream(tmpFile.getPath())); Enumeration<? extends ZipEntry> entries = inZip.entries(); while (entries.hasMoreElements()) { ZipEntry e = entries.nextElement(); outZip.putNextEntry(e); if (!e.isDirectory()) { File f = new File(sPath + "/" + e.getName()); if (f.exists()) { copy(new FileInputStream(f.getPath()), outZip); } else { copy(inZip.getInputStream(e), outZip); } } outZip.closeEntry(); } inZip.close(); outZip.close(); return tmpFile; }
From source file:Main.java
/*** * Extract zipfile to outdir with complete directory structure * @param zipfile Input .zip file/* w ww .j a va 2 s .co m*/ * @param outdir Output directory */ public static void extract(InputStream zipfile, File outdir) { try { ZipInputStream zin = new ZipInputStream(zipfile); ZipEntry entry; String name, dir; Log.i("OF", "uncompressinggggg "); while ((entry = zin.getNextEntry()) != null) { name = entry.getName(); if (entry.isDirectory()) { mkdirs(outdir, name); continue; } /* this part is necessary because file entry can come before * directory entry where is file located * i.e.: * /foo/foo.txt * /foo/ */ dir = dirpart(name); if (dir != null) mkdirs(outdir, dir); extractFile(zin, outdir, name); } zin.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.google.gdt.eclipse.designer.webkit.WebKitSupportWin32.java
private static void extract(ZipFile zipFile) throws Exception { // remove any possibly corrupted contents FileUtils.deleteQuietly(WEBKIT_DIR); WEBKIT_DIR.mkdirs();//from w w w.ja v a2s .c o m Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (entry.isDirectory()) { new File(WEBKIT_DIR, entry.getName()).mkdirs(); continue; } InputStream inputStream = zipFile.getInputStream(entry); File outputFile = new File(WEBKIT_DIR, entry.getName()); FileOutputStream outputStream = new FileOutputStream(outputFile); IOUtils.copy(inputStream, outputStream); IOUtils.closeQuietly(inputStream); IOUtils.closeQuietly(outputStream); } }
From source file:com.cloudbees.plugins.deployer.CloudbeesDeployWarTest.java
public static void assertOnArchive(InputStream inputStream) throws IOException { List<String> fileNames = new ArrayList<String>(); ZipInputStream zipInputStream = null; try {// w w w . j a v a 2s . c o m zipInputStream = new ZipInputStream(inputStream); ZipEntry zipEntry = zipInputStream.getNextEntry(); while (zipEntry != null) { fileNames.add(zipEntry.getName()); zipEntry = zipInputStream.getNextEntry(); } } finally { IOUtils.closeQuietly(zipInputStream); } assertTrue(fileNames.contains("META-INF/maven/org.olamy.puzzle.translate/translate-puzzle-webapp/pom.xml")); assertTrue(fileNames.contains("WEB-INF/lib/javax.inject-1.jar")); }
From source file:com.dustindoloff.s3websitedeploy.Main.java
private static boolean upload(final AmazonS3 s3Client, final String bucket, final ZipFile zipFile) { boolean failed = false; final ObjectMetadata data = new ObjectMetadata(); final Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { final ZipEntry entry = entries.nextElement(); data.setContentLength(entry.getSize()); try {/*from w w w . jav a2 s. c o m*/ s3Client.putObject(bucket, entry.getName(), zipFile.getInputStream(entry), data); } catch (final AmazonClientException | IOException e) { failed = true; } } return !failed; }
From source file:net.chris54721.infinitycubed.utils.Utils.java
public static void unzip(File zipFile, File outputFolder) { InputStream in = null;/* w ww . ja v a2 s.com*/ OutputStream out = null; try { ZipFile zip = new ZipFile(zipFile); Enumeration<? extends ZipEntry> entries = zip.entries(); if (!outputFolder.isDirectory()) outputFolder.mkdirs(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); File entryTarget = new File(outputFolder, entry.getName()); entryTarget.getParentFile().mkdirs(); if (entry.isDirectory()) entryTarget.mkdirs(); else { in = zip.getInputStream(entry); out = new FileOutputStream(entryTarget); IOUtils.copy(in, out); } } } catch (Exception e) { LogHelper.error("Failed extracting " + zipFile.getName(), e); } finally { if (in != null) IOUtils.closeQuietly(in); if (out != null) IOUtils.closeQuietly(out); } }
From source file:ZipFileIO.java
/** * Extract zip file to destination folder. * //ww w .j a va 2 s . co m * @param file * zip file to extract * @param destination * destinatin folder */ public static void extract(File file, File destination) throws IOException { ZipInputStream in = null; OutputStream out = null; try { // Open the ZIP file in = new ZipInputStream(new FileInputStream(file)); // Get the first entry ZipEntry entry = null; while ((entry = in.getNextEntry()) != null) { String outFilename = entry.getName(); // Open the output file if (entry.isDirectory()) { new File(destination, outFilename).mkdirs(); } else { out = new FileOutputStream(new File(destination, outFilename)); // Transfer bytes from the ZIP file to the output file byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } // Close the stream out.close(); } } } finally { // Close the stream if (in != null) { in.close(); } if (out != null) { out.close(); } } }