List of usage examples for java.util.zip ZipOutputStream close
public void close() throws IOException
From source file:de.nx42.maps4cim.util.Compression.java
/** * Compresses the input file using the zip file format and stores the * resulting zip file in the desired location * @param input the file to compress/* w w w . j a v a 2s . c o m*/ * @param zipOutput the resulting zip file * @return the resulting zip file * @throws IOException if there is an error accessing the input file or * writing the output zip file */ public static File storeAsZip(File input, File zipOutput) throws IOException { // create new zip output stream ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipOutput)); ZipEntry ze = new ZipEntry(input.getName()); zos.putNextEntry(ze); // use file as input stream and copy bytes InputStream in = new FileInputStream(input); ByteStreams.copy(in, zos); // close current zip entry and all streams zos.closeEntry(); in.close(); zos.close(); return zipOutput; }
From source file:com.microsoft.azurebatch.jenkins.utils.ZipHelper.java
/** * Zip folder//from w w w.ja v a 2 s. c om * @param srcFolderPath source folder path * @param outputZipPath output zip file path * @throws FileNotFoundException * @throws IOException */ public static void zipFolder(String srcFolderPath, String outputZipPath) throws FileNotFoundException, IOException { ZipOutputStream zip = null; FileOutputStream fileWriter = null; // Create the output stream to zip file result fileWriter = new FileOutputStream(outputZipPath); zip = new ZipOutputStream(fileWriter); // Add the folder to the zip addFolderToZip("", srcFolderPath, zip); // Close the zip objects zip.flush(); zip.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();// www .ja va 2s.c o m fileInputStream.close(); } zipOutputStream.close(); }
From source file:com.mc.printer.model.utils.ZipHelper.java
/** * ZIP// ww w. j a v a 2 s . c o m * * @param sourcePath * @param zipPath ?zip?? */ public static void createZip(String sourcePath, String zipPath) { FileOutputStream fos = null; ZipOutputStream zos = null; try { fos = new FileOutputStream(zipPath); zos = new ZipOutputStream(fos); writeZip(new File(sourcePath), "", zos); } catch (FileNotFoundException e) { log.error("create zip file failed.", e); } finally { try { if (zos != null) { zos.close(); } if (fos != null) { fos.close(); } } catch (IOException e) { log.error("create zip file failed.", e); } } }
From source file:azkaban.utils.Utils.java
public static void zip(File input, File output) throws IOException { FileOutputStream out = new FileOutputStream(output); ZipOutputStream zOut = new ZipOutputStream(out); try {//from www . java2 s. c o m zipFile("", input, zOut); } finally { zOut.close(); } }
From source file:com.algomedica.service.LicenseManagerServiceImpl.java
public static byte[] zipBytes(String filename, byte[] input) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ZipOutputStream zos = new ZipOutputStream(baos); ZipEntry entry = new ZipEntry(filename); entry.setSize(input.length);// w ww .java 2s . c o m zos.putNextEntry(entry); zos.write(input); zos.closeEntry(); zos.close(); return baos.toByteArray(); }
From source file:nz.ac.otago.psyanlab.common.util.FileUtils.java
public static void compress(File destination, Experiment experiment, File workingDir) throws IOException { ZipOutputStream out = new ZipOutputStream(new FileOutputStream(destination)); try {/*from ww w.j ava 2 s . c om*/ writeExperimentDefinitionToArchive(out, copyAssetsToArchive(out, experiment, workingDir)); } finally { out.close(); } }
From source file:net.vhati.modmanager.cli.SlipstreamCLI.java
/** * Returns a temporary zip made from a directory. * * Empty subdirs will be omitted.//from w w w . j a v a 2 s. c o m * The archive will be not be deleted on exit (handle that elsewhere). */ private static File createTempMod(File dir) throws IOException { File tempFile = File.createTempFile(dir.getName() + "_temp-", ".zip"); FileOutputStream fos = null; try { fos = new FileOutputStream(tempFile); ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(fos)); addDirToArchive(zos, dir, null); zos.close(); } finally { try { if (fos != null) fos.close(); } catch (IOException e) { } } return tempFile; }
From source file:com.ibm.amc.FileManager.java
public static File compress(File pathToCompress) { try {//from ww w. jav a 2s . c o m File zipFile = new File(pathToCompress.getCanonicalPath() + ZIP_EXTENSION); FileOutputStream fileOutputStream = new FileOutputStream(zipFile); CheckedOutputStream cos = new CheckedOutputStream(fileOutputStream, new CRC32()); ZipOutputStream out = new ZipOutputStream(cos); String basedir = ""; compress(pathToCompress, out, basedir); out.close(); return zipFile; } catch (Exception e) { throw new AmcRuntimeException(e); } }
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 . ja va2s . c om*/ 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(); }