List of usage examples for java.util.zip ZipOutputStream close
public void close() throws IOException
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")); }/*from w w w . j a v a2s . c o m*/ } 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:Main.java
private static void zipDir(String zipFileName, String dir) throws Exception { File dirObj = new File(dir); ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFileName)); System.out.println("Creating : " + zipFileName); addDir(dirObj, out);/*from w w w . j a v a2 s. c om*/ out.close(); }
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(); return os.toByteArray(); }
From source file:Main.java
public static final void zipDirectory(File directory, File zip) throws IOException { ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zip)); zip(directory, directory.getParentFile(), zos); zos.close(); }
From source file:Main.java
public static void compressDir(File file) throws IOException { FileOutputStream f = new FileOutputStream(file.getParent() + file.getName() + ".zip"); CheckedOutputStream cs = new CheckedOutputStream(f, new Adler32()); ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(cs)); compressDir(file, out, file.getAbsolutePath()); out.flush();//from www . ja va2 s. c o m out.close(); }
From source file:Main.java
public static void zipDir(String zipFileName, String dir) throws Exception { ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(zipFileName)); zipDir(dir, zipOut);/*w w w.ja v a 2s . c o m*/ zipOut.close(); }
From source file:com.jaspersoft.jasperserver.jrsh.common.ZipUtil.java
public static File pack(String directory) { File dir = new File(directory); if (!dir.isDirectory()) { throw new DirectoryDoesNotExistException(directory); }// w w w. j av a2 s . com directory = StringUtils.chomp(directory, separator); String outputFileName = directory.concat(".zip"); try { File arch = new File(outputFileName); FileOutputStream fos = null; fos = new FileOutputStream(arch); ZipOutputStream zos = new ZipOutputStream(fos); addFiles(zos, directory, directory); zos.close(); return arch; } catch (Exception unimportant) { throw new CannotPackDirectoryException(); } }
From source file:Main.java
public static byte[] zipDir(String dir) throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zipOut = new ZipOutputStream(out); zipDir(dir, zipOut);//w ww. j a v a 2s . c om byte[] zipped = out.toByteArray(); zipOut.close(); return zipped; }
From source file:nl.clockwork.common.util.Utils.java
public static byte[] zip(String name, String content) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zout = new ZipOutputStream(out); ZipEntry entry = new ZipEntry(name); zout.putNextEntry(entry);//from w w w. j a v a2 s.c om zout.write(content.getBytes()); zout.close(); return out.toByteArray(); }
From source file:FolderZiper.java
static public void zipFolder(String srcFolder, String destZipFile) throws Exception { ZipOutputStream zip = null; FileOutputStream fileWriter = null; fileWriter = new FileOutputStream(destZipFile); zip = new ZipOutputStream(fileWriter); addFolderToZip("", srcFolder, zip); zip.flush();// www. jav a 2 s. co m zip.close(); }