List of usage examples for java.util.zip ZipOutputStream ZipOutputStream
public ZipOutputStream(OutputStream out)
From source file:brut.directory.ZipUtils.java
public static void zipFolders(final File folder, final File zip, final File assets, final Collection<String> doNotCompress) throws BrutException, IOException { mDoNotCompress = doNotCompress;//from w ww .ja va2s. co m ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(zip)); zipFolders(folder, zipOutputStream); // We manually set the assets because we need to retain the folder structure if (assets != null) { processFolder(assets, zipOutputStream, assets.getPath().length() - 6); } zipOutputStream.close(); }
From source file:FileUtil.java
/** * Zip up a directory/*from w ww . java2 s .c o m*/ * * @param directory * @param zipName * @throws IOException */ public static void zipDir(String directory, String zipName) throws IOException { // create a ZipOutputStream to zip the data to ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipName)); String path = ""; zipDir(directory, zos, path); // close the stream zos.close(); }
From source file:com.splout.db.common.CompressorUtil.java
public static void createZip(File dir, File out, IOFileFilter filefilter, IOFileFilter dirFilter) throws IOException { Collection<File> files = FileUtils.listFiles(dir, filefilter, dirFilter); out.delete();/*from w w w . j a v a2 s.c o m*/ ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(out)); byte[] buf = new byte[1024]; for (File f : files) { ZipEntry ze = new ZipEntry(getRelativePath(f, dir)); zos.putNextEntry(ze); InputStream is = new FileInputStream(f); int cnt; while ((cnt = is.read(buf)) >= 0) { zos.write(buf, 0, cnt); } is.close(); zos.flush(); zos.closeEntry(); } zos.close(); }
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);//from w w w .j a v a 2 s. co m byte[] zipped = out.toByteArray(); zipOut.close(); return zipped; }
From source file:com.smash.revolance.ui.model.helper.ArchiveHelper.java
public static File buildArchive(File archive, File... files) throws FileNotFoundException { FileOutputStream fos = new FileOutputStream(archive); ZipOutputStream zos = new ZipOutputStream(fos); int bytesRead; byte[] buffer = new byte[1024]; CRC32 crc = new CRC32(); for (File file : files) { if (!file.exists()) { System.err.println("Skipping: " + file); continue; }//from ww w . j ava2s . c om BufferedInputStream bis = null; try { bis = new BufferedInputStream(new FileInputStream(file)); crc.reset(); while ((bytesRead = bis.read(buffer)) != -1) { crc.update(buffer, 0, bytesRead); } bis.close(); // Reset to beginning of input stream bis = new BufferedInputStream(new FileInputStream(file)); String entryPath = FileHelper.getRelativePath(archive.getParentFile(), file); ZipEntry entry = new ZipEntry(entryPath); entry.setMethod(ZipEntry.STORED); entry.setCompressedSize(file.length()); entry.setSize(file.length()); entry.setCrc(crc.getValue()); zos.putNextEntry(entry); while ((bytesRead = bis.read(buffer)) != -1) { zos.write(buffer, 0, bytesRead); } } catch (FileNotFoundException e) { } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } finally { IOUtils.closeQuietly(bis); } } IOUtils.closeQuietly(zos); return archive; }
From source file:Main.java
public void doZip(String filename, String zipfilename) throws Exception { byte[] buf = new byte[1024]; FileInputStream fis = new FileInputStream(filename); fis.read(buf, 0, buf.length);//from w w w . ja v a 2 s . c o m CRC32 crc = new CRC32(); ZipOutputStream s = new ZipOutputStream((OutputStream) new FileOutputStream(zipfilename)); s.setLevel(6); ZipEntry entry = new ZipEntry(filename); entry.setSize((long) buf.length); crc.reset(); crc.update(buf); entry.setCrc(crc.getValue()); s.putNextEntry(entry); s.write(buf, 0, buf.length); s.finish(); s.close(); }
From source file:Main.java
public void doZip(String filename, String zipfilename) throws Exception { byte[] buf = new byte[1024]; FileInputStream fis = new FileInputStream(filename); fis.read(buf, 0, buf.length);/*from w ww . j a v a 2 s . com*/ CRC32 crc = new CRC32(); ZipOutputStream s = new ZipOutputStream((OutputStream) new FileOutputStream(zipfilename)); s.setLevel(6); ZipEntry entry = new ZipEntry(filename); entry.setSize((long) buf.length); entry.setMethod(ZipEntry.DEFLATED); crc.reset(); crc.update(buf); entry.setCrc(crc.getValue()); s.putNextEntry(entry); s.write(buf, 0, buf.length); s.finish(); s.close(); }
From source file:Main.java
public void doZip(String filename, String zipfilename) throws Exception { byte[] buf = new byte[1024]; FileInputStream fis = new FileInputStream(filename); fis.read(buf, 0, buf.length);// w w w .j a va 2 s . co m CRC32 crc = new CRC32(); ZipOutputStream s = new ZipOutputStream((OutputStream) new FileOutputStream(zipfilename)); s.setLevel(6); ZipEntry entry = new ZipEntry(filename); entry.setSize((long) buf.length); entry.setTime(new Date().getTime()); crc.reset(); crc.update(buf); entry.setCrc(crc.getValue()); s.putNextEntry(entry); s.write(buf, 0, buf.length); s.finish(); s.close(); }
From source file:Main.java
final static private boolean createZipFile(String out, String... in) { InputStream is = null;//w ww .j a v a2 s . c om ZipOutputStream zos = null; try { zos = new ZipOutputStream(new FileOutputStream(out)); } catch (FileNotFoundException e2) { e2.printStackTrace(); } try { for (int i = 0; i < in.length; i++) { is = new FileInputStream(in[i]); ZipEntry ze = new ZipEntry(in[i]); zos.putNextEntry(ze); int len = 0; byte[] buf = new byte[1024]; while ((len = is.read(buf)) != -1) { zos.write(buf, 0, len); } is.close(); zos.closeEntry(); } zos.close(); } catch (IOException e) { e.printStackTrace(); return false; } return true; }
From source file:ZipHandler.java
/** * makes a zip file named <xmlFileName> from <xmlURL> at path <zipURL> * @param zipURL// w w w .ja v a2 s .c o m * @param xmlURL * @param xmlFileName */ public static void makeZip(String zipURL, String xmlURL, String xmlFileName) throws IOException { FileOutputStream fos = new FileOutputStream(new File(zipURL)); ZipOutputStream zos = new ZipOutputStream(fos); // zos.setLevel(); FileInputStream fis = new FileInputStream(xmlURL); zos.putNextEntry(new ZipEntry(xmlFileName + ".xml")); writeInOutputStream(fis, zos); String bpath = "c:\\"; FileInputStream fisBLOB = createInputStream(bpath); zos.putNextEntry(new ZipEntry("blob.lob")); writeInOutputStream(fisBLOB, zos); zos.closeEntry(); String cpath = "c:\\"; FileInputStream fisCLOB = createInputStream(cpath); zos.putNextEntry(new ZipEntry("clob.lob")); writeInOutputStream(fisCLOB, zos); zos.closeEntry(); fis.close(); fisCLOB.close(); fisBLOB.close(); zos.close(); fos.close(); }