List of usage examples for java.util.zip ZipEntry ZipEntry
public ZipEntry(ZipEntry e)
From source file:com.textocat.textokit.postagger.opennlp.PackageModelZipAsArtifact.java
public static void main(String[] args) throws IOException { PackageModelZipAsArtifact cli = new PackageModelZipAsArtifact(); new JCommander(cli, args); Path inputZipPath = Paths.get(cli.inputZipPathStr); if (!Files.isRegularFile(inputZipPath)) { System.err.println(inputZipPath + " is not an existing file."); System.exit(1);/*from w ww . j a v a2s .com*/ } POSModelJarManifestBean manifestBean = new POSModelJarManifestBean(cli.languageCode, cli.modelVariant); Path outputJarPath = inputZipPath .resolveSibling(FilenameUtils.getBaseName(inputZipPath.getFileName().toString()) + ".jar"); try (OutputStream out = new BufferedOutputStream(Files.newOutputStream(outputJarPath))) { JarOutputStream jout = new JarOutputStream(out, manifestBean.toManifest()); jout.putNextEntry(new ZipEntry(ClasspathPOSModelHolder.getClassPath(manifestBean.getLanguageCode(), manifestBean.getModelVariant()))); FileUtils.copyFile(inputZipPath.toFile(), jout); jout.closeEntry(); jout.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 w w w . j av a 2 s .com*/ } 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:com.alexoree.jenkins.Main.java
public static void main(String[] args) throws Exception { // create Options object Options options = new Options(); options.addOption("t", false, "throttle the downloads, waits 5 seconds in between each d/l"); // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("jenkins-sync", options); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); boolean throttle = cmd.hasOption("t"); String plugins = "https://updates.jenkins-ci.org/latest/"; List<String> ps = new ArrayList<String>(); Document doc = Jsoup.connect(plugins).get(); for (Element file : doc.select("td a")) { //System.out.println(file.attr("href")); if (file.attr("href").endsWith(".hpi") || file.attr("href").endsWith(".war")) { ps.add(file.attr("href")); }//w ww .j a v a 2 s .c om } File root = new File("."); //https://updates.jenkins-ci.org/latest/AdaptivePlugin.hpi new File("./latest").mkdirs(); //output zip file String zipFile = "jenkinsSync.zip"; // create byte buffer byte[] buffer = new byte[1024]; FileOutputStream fos = new FileOutputStream(zipFile); ZipOutputStream zos = new ZipOutputStream(fos); //download the plugins for (int i = 0; i < ps.size(); i++) { System.out.println("[" + i + "/" + ps.size() + "] downloading " + plugins + ps.get(i)); String outputFile = download(root.getAbsolutePath() + "/latest/" + ps.get(i), plugins + ps.get(i)); FileInputStream fis = new FileInputStream(outputFile); // begin writing a new ZIP entry, positions the stream to the start of the entry data zos.putNextEntry(new ZipEntry(outputFile.replace(root.getAbsolutePath(), "") .replace("updates.jenkins-ci.org/", "").replace("https:/", ""))); int length; while ((length = fis.read(buffer)) > 0) { zos.write(buffer, 0, length); } zos.closeEntry(); fis.close(); if (throttle) Thread.sleep(WAIT); new File(root.getAbsolutePath() + "/latest/" + ps.get(i)).deleteOnExit(); } //download the json metadata plugins = "https://updates.jenkins-ci.org/"; ps = new ArrayList<String>(); doc = Jsoup.connect(plugins).get(); for (Element file : doc.select("td a")) { //System.out.println(file.attr("href")); if (file.attr("href").endsWith(".json")) { ps.add(file.attr("href")); } } for (int i = 0; i < ps.size(); i++) { download(root.getAbsolutePath() + "/" + ps.get(i), plugins + ps.get(i)); FileInputStream fis = new FileInputStream(root.getAbsolutePath() + "/" + ps.get(i)); // begin writing a new ZIP entry, positions the stream to the start of the entry data zos.putNextEntry(new ZipEntry(plugins + ps.get(i))); int length; while ((length = fis.read(buffer)) > 0) { zos.write(buffer, 0, length); } zos.closeEntry(); fis.close(); new File(root.getAbsolutePath() + "/" + ps.get(i)).deleteOnExit(); if (throttle) Thread.sleep(WAIT); } // close the ZipOutputStream zos.close(); }
From source file:com.textocat.textokit.morph.opencorpora.resource.XmlDictionaryPSP.java
public static void main(String[] args) throws Exception { XmlDictionaryPSP cfg = new XmlDictionaryPSP(); new JCommander(cfg, args); MorphDictionaryImpl dict = new MorphDictionaryImpl(); DictionaryExtension ext = cfg.dictExtensionClass.newInstance(); FileInputStream fis = FileUtils.openInputStream(cfg.dictXmlFile); try {/* ww w . ja v a 2 s. c o m*/ new XmlDictionaryParser(dict, ext, fis).run(); } finally { IOUtils.closeQuietly(fis); } System.out.println("Preparing to serialization..."); long timeBefore = currentTimeMillis(); OutputStream fout = new BufferedOutputStream(FileUtils.openOutputStream(cfg.outputJarFile), 8192 * 8); Manifest manifest = new Manifest(); manifest.getMainAttributes().putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1.0"); manifest.getMainAttributes().putValue(OpencorporaMorphDictionaryAPI.ME_OPENCORPORA_DICTIONARY_VERSION, dict.getVersion()); manifest.getMainAttributes().putValue(OpencorporaMorphDictionaryAPI.ME_OPENCORPORA_DICTIONARY_REVISION, dict.getRevision()); manifest.getMainAttributes().putValue(OpencorporaMorphDictionaryAPI.ME_OPENCORPORA_DICTIONARY_VARIANT, cfg.variant); String dictEntryName = String.format( OpencorporaMorphDictionaryAPI.FILENAME_PATTERN_OPENCORPORA_SERIALIZED_DICT, dict.getVersion(), dict.getRevision(), cfg.variant); JarOutputStream jarOut = new JarOutputStream(fout, manifest); jarOut.putNextEntry(new ZipEntry(dictEntryName)); ObjectOutputStream serOut = new ObjectOutputStream(jarOut); try { serOut.writeObject(dict.getGramModel()); serOut.writeObject(dict); } finally { serOut.flush(); jarOut.closeEntry(); serOut.close(); } System.out.println(String.format("Serialization finished in %s ms.\nOutput size: %s bytes", currentTimeMillis() - timeBefore, cfg.outputJarFile.length())); }
From source file:Main.java
public static byte[] compressZip(byte bytes[]) throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); ZipOutputStream zipos = new ZipOutputStream(os); zipos.putNextEntry(new ZipEntry("ZIP")); zipos.write(bytes, 0, bytes.length); zipos.close();/* w w w. j a v a 2s . c o m*/ return os.toByteArray(); }
From source file:Main.java
public static void doEntry(Context context, ZipOutputStream zout, int resId, String dest) throws Exception { InputStream in = null;// w w w. j ava 2 s .com try { zout.putNextEntry(new ZipEntry(dest)); copyStream(in = context.getResources().openRawResource(resId), zout); } finally { zout.closeEntry(); in.close(); } }
From source file:Main.java
private static void compressFile(File file, ZipOutputStream out, String basedir) { if (!file.exists()) { return;/*from ww w. j a v a2s .com*/ } try { BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file)); ZipEntry entry = new ZipEntry(basedir + file.getName()); out.putNextEntry(entry); int count; byte data[] = new byte[BUFFER]; while ((count = bis.read(data, 0, BUFFER)) != -1) { out.write(data, 0, count); } bis.close(); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:Main.java
public static void compressFile(File file, File fileCompressed) throws IOException { byte[] buffer = new byte[SIZE_OF_BUFFER]; ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(fileCompressed)); FileInputStream fileInputStream = new FileInputStream(file); zipOutputStream.putNextEntry(new ZipEntry(file.getPath())); int size;//from w w w . j ava2 s . c om while ((size = fileInputStream.read(buffer)) > 0) zipOutputStream.write(buffer, 0, size); zipOutputStream.closeEntry(); fileInputStream.close(); zipOutputStream.close(); }
From source file:Main.java
public static void compressFiles(File files[], File fileCompressed) throws IOException { byte[] buffer = new byte[SIZE_OF_BUFFER]; ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(fileCompressed)); for (int i = 0; i < files.length; i++) { FileInputStream fileInputStream = new FileInputStream(files[i]); zipOutputStream.putNextEntry(new ZipEntry(files[i].getPath())); int size; while ((size = fileInputStream.read(buffer)) > 0) zipOutputStream.write(buffer, 0, size); zipOutputStream.closeEntry();//from ww w.j a v a 2 s .c o m fileInputStream.close(); } zipOutputStream.close(); }
From source file:Main.java
private static byte[] createZip(Map<String, byte[]> files) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ZipOutputStream zf = new ZipOutputStream(bos); Iterator<String> it = files.keySet().iterator(); String fileName = null;//from ww w . j a v a 2 s.c o m ZipEntry ze = null; while (it.hasNext()) { fileName = it.next(); ze = new ZipEntry(fileName); zf.putNextEntry(ze); zf.write(files.get(fileName)); } zf.close(); return bos.toByteArray(); }