List of usage examples for java.util.zip ZipEntry getName
public String getName()
From source file:Main.java
public static void main(String[] args) throws Exception { String zipname = "d.zip"; CheckedInputStream checksum = new CheckedInputStream(new FileInputStream(zipname), new Adler32()); ZipInputStream zis = new ZipInputStream(new BufferedInputStream(checksum)); ZipEntry entry; while ((entry = zis.getNextEntry()) != null) { System.out.println("Unzipping: " + entry.getName()); int size; byte[] buffer = new byte[2048]; BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(entry.getName()), buffer.length);/*from w ww .j av a 2 s .c o m*/ while ((size = zis.read(buffer, 0, buffer.length)) != -1) { bos.write(buffer, 0, size); } bos.flush(); bos.close(); } zis.close(); System.out.println("Checksum = " + checksum.getChecksum().getValue()); }
From source file:Main.java
public static void main(String[] args) throws Exception { String destinationname = "d:\\"; byte[] buf = new byte[1024]; ZipInputStream zipinputstream = null; ZipEntry zipentry; zipinputstream = new ZipInputStream(new FileInputStream("fileName")); zipentry = zipinputstream.getNextEntry(); while (zipentry != null) { String entryName = zipentry.getName(); FileOutputStream fileoutputstream; File newFile = new File(entryName); String directory = newFile.getParent(); if (directory == null) { if (newFile.isDirectory()) break; }/* w w w .ja va2s.c o m*/ fileoutputstream = new FileOutputStream(destinationname + entryName); int n; while ((n = zipinputstream.read(buf, 0, 1024)) > -1) { fileoutputstream.write(buf, 0, n); } fileoutputstream.close(); zipinputstream.closeEntry(); zipentry = zipinputstream.getNextEntry(); } zipinputstream.close(); }
From source file:com.heliosdecompiler.appifier.Appifier.java
public static void main(String[] args) throws Throwable { if (args.length == 0) { System.out.println("An input JAR must be specified"); return;//from ww w. j a va 2 s. c om } File in = new File(args[0]); if (!in.exists()) { System.out.println("Input not found"); return; } String outName = args[0]; outName = outName.substring(0, outName.length() - ".jar".length()) + "-appified.jar"; File out = new File(outName); if (out.exists()) { if (!out.delete()) { System.out.println("Could not delete out file"); return; } } try (ZipOutputStream outstream = new ZipOutputStream(new FileOutputStream(out)); ZipFile zipFile = new ZipFile(in)) { { ZipEntry systemHook = new ZipEntry("com/heliosdecompiler/appifier/SystemHook.class"); outstream.putNextEntry(systemHook); outstream.write(SystemHookDump.dump()); outstream.closeEntry(); } Enumeration<? extends ZipEntry> enumeration = zipFile.entries(); while (enumeration.hasMoreElements()) { ZipEntry next = enumeration.nextElement(); if (!next.isDirectory()) { ZipEntry result = new ZipEntry(next.getName()); outstream.putNextEntry(result); if (next.getName().endsWith(".class")) { byte[] classBytes = IOUtils.toByteArray(zipFile.getInputStream(next)); outstream.write(transform(classBytes)); } else { IOUtils.copy(zipFile.getInputStream(next), outstream); } outstream.closeEntry(); } } } }
From source file:Main.java
public static void main(String[] args) throws Exception { ZipFile zf = new ZipFile("ziptest.zip"); // Get the enumeration for all zip entries and loop through them Enumeration<? extends ZipEntry> e = zf.entries(); ZipEntry entry = null; while (e.hasMoreElements()) { entry = e.nextElement();/*from w w w . ja va 2s . c om*/ // Get the input stream for the current zip entry InputStream is = zf.getInputStream(entry); /* Read data for the entry using the is object */ // Print the name of the entry System.out.println(entry.getName()); } }
From source file:JarMaker.java
/** * Test/*from w w w .j a v a 2 s . c om*/ * @param args * @throws Exception */ public static void main(String args[]) throws Exception { String[] in = new String[2]; in[1] = "E:\\pkuas03\\pkuas_51\\repository\\deployed\\ecperf.ear\\corp.jar"; in[0] = "E:\\pkuas03\\pkuas_51\\repository\\deployed\\ecperf.ear\\orders.jar"; String[] fs = new String[1]; fs[0] = "E:\\pkuas03\\pkuas_51\\repository\\deployed\\ecperf.ear\\META-INF\\application.xml"; String[] pres = new String[1]; pres[0] = "META-INF"; combineJars("e:\\111.jar", in, new EntryFilter() { public boolean accept(ZipEntry entry) { if (entry.getName().endsWith("ejb-jar.xml")) return false; return true; } }, fs, pres); }
From source file:kilim.tools.DumpClass.java
public static void main(String[] args) throws IOException { String name = args.length == 2 ? args[1] : args[0]; if (name.endsWith(".jar")) { try {//w w w . j a va 2 s .c o m Enumeration<JarEntry> e = new JarFile(name).entries(); while (e.hasMoreElements()) { ZipEntry en = (ZipEntry) e.nextElement(); String n = en.getName(); if (!n.endsWith(".class")) continue; n = n.substring(0, n.length() - 6).replace('/', '.'); new DumpClass(n); } } catch (Exception e) { e.printStackTrace(); } } else { new DumpClass(name); } }
From source file:com.adobe.aem.demomachine.communities.Loader.java
public static void main(String[] args) { String hostname = null;/*www .j a v a 2s .c o m*/ String port = null; String altport = null; String csvfile = null; String analytics = null; String adminPassword = "admin"; boolean reset = false; boolean configure = false; boolean minimize = false; boolean noenablement = true; int maxretries = MAXRETRIES; // Command line options for this tool Options options = new Options(); options.addOption("h", true, "Hostname"); options.addOption("p", true, "Port"); options.addOption("a", true, "Alternate Port"); options.addOption("f", true, "CSV file"); options.addOption("r", false, "Reset"); options.addOption("u", true, "Admin Password"); options.addOption("c", false, "Configure"); options.addOption("m", false, "Minimize"); options.addOption("e", false, "No Enablement"); options.addOption("s", true, "Analytics Endpoint"); options.addOption("t", false, "Analytics"); options.addOption("w", false, "Retry"); CommandLineParser parser = new BasicParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("h")) { hostname = cmd.getOptionValue("h"); } if (cmd.hasOption("p")) { port = cmd.getOptionValue("p"); } if (cmd.hasOption("a")) { altport = cmd.getOptionValue("a"); } if (cmd.hasOption("f")) { csvfile = cmd.getOptionValue("f"); } if (cmd.hasOption("u")) { adminPassword = cmd.getOptionValue("u"); } if (cmd.hasOption("t")) { if (cmd.hasOption("s")) { analytics = cmd.getOptionValue("s"); } } if (cmd.hasOption("r")) { reset = true; } if (cmd.hasOption("w")) { maxretries = Integer.parseInt(cmd.getOptionValue("w")); } if (cmd.hasOption("c")) { configure = true; } if (cmd.hasOption("m")) { minimize = true; } if (cmd.hasOption("e")) { noenablement = false; } if (csvfile == null || port == null || hostname == null) { System.out.println( "Request parameters: -h hostname -p port -a alternateport -u adminPassword -f path_to_CSV_file -r (true|false, delete content before import) -c (true|false, post additional properties)"); System.exit(-1); } } catch (ParseException ex) { logger.error(ex.getMessage()); } logger.debug("AEM Demo Loader: Processing file " + csvfile); try { // Reading and processing the CSV file, stand alone or as part of a ZIP file if (csvfile != null && csvfile.toLowerCase().endsWith(".zip")) { ZipFile zipFile = new ZipFile(csvfile); ZipInputStream stream = new ZipInputStream(new FileInputStream(csvfile)); ZipEntry zipEntry; while ((zipEntry = stream.getNextEntry()) != null) { if (!zipEntry.isDirectory() && zipEntry.getName().toLowerCase().endsWith(".csv")) { InputStream is = zipFile.getInputStream(zipEntry); BufferedReader in = new BufferedReader(new InputStreamReader(is, "UTF-8")); processLoading(null, in, hostname, port, altport, adminPassword, analytics, reset, configure, minimize, noenablement, csvfile, maxretries); } } try { stream.close(); zipFile.close(); } catch (IOException ioex) { //omitted. } } else if (csvfile.toLowerCase().endsWith(".csv")) { Reader in = new FileReader(csvfile); processLoading(null, in, hostname, port, altport, adminPassword, analytics, reset, configure, minimize, noenablement, csvfile, maxretries); } } catch (IOException e) { logger.error(e.getMessage()); } }
From source file:Main.java
public static String getEntryName(ZipEntry entry) { try {// w ww . ja v a2 s. co m return new String(entry.getName().getBytes("GB2312"), "8859_1"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static String getEntryName(ZipEntry entry) throws UnsupportedEncodingException { return new String(entry.getName().getBytes("GB2312"), "8859_1"); }
From source file:Main.java
private static ZipEntry findRootInstallTxt(List<ZipEntry> entries) { List<ZipEntry> iz = new ArrayList<ZipEntry>(); for (ZipEntry e : entries) { if (e.getName().contains("install.txt")) iz.add(e);/*from w w w . j av a2 s. c o m*/ } if (iz.size() == 1) return iz.get(0); //Log.d(TAG, "has " + iz.size() + " install.txts"); // sort to get shortest one Collections.sort(iz, zipFilenameCompare); //Log.d(TAG, "first" + iz.get(0).getName() + ", last" + iz.get(iz.size() -1).getName()); return iz.get(0); }