Example usage for java.util.zip ZipOutputStream close

List of usage examples for java.util.zip ZipOutputStream close

Introduction

In this page you can find the example usage for java.util.zip ZipOutputStream close.

Prototype

public void close() throws IOException 

Source Link

Document

Closes the ZIP output stream as well as the stream being filtered.

Usage

From source file:FileUtil.java

/**
 * Zip up a directory//  w  ww .  ja va  2  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:edu.clemson.cs.nestbed.common.util.ZipUtils.java

public static void zipDirectory(File directory, File output) throws IOException {
    ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(output));
    zipDirectory(directory, directory.getName(), zos);
    zos.close();
}

From source file:Main.java

static public File zipFolder(File srcFolder, String destZipFile) throws Exception {
    final File file = new File(srcFolder, destZipFile);
    final ZipOutputStream zip = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
    try {/*from w ww. ja va  2s.co  m*/
        addFolderToZip("", srcFolder, zip, destZipFile);
    } finally {
        zip.close();
    }
    return file;
}

From source file:Main.java

/**
 * creates azip file from an directory with all subfolders
 * @param dir/*  w  w w .j  a  v  a  2  s .  co m*/
 * @param zipFileName
 * @throws IOException
 */
public static void createZipFile(String dir, String zipFileName) throws IOException {
    String dirFile = dir + "/" + zipFileName;
    ZipOutputStream zipOut = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(dirFile)));
    try {
        zipDir(dir, zipOut, zipFileName);
    } finally {
        zipOut.close();
    }
}

From source file:nz.co.fortytwo.freeboard.installer.ZipUtils.java

public static void zip(File sourceDir, File zipFile) {

    try {//from   www .  j  a  v a2s  .c o m
        // create object of FileOutputStream
        FileOutputStream fout = new FileOutputStream(zipFile);

        // create object of ZipOutputStream from FileOutputStream
        ZipOutputStream zout = new ZipOutputStream(fout);
        addDirectory(zout, sourceDir, sourceDir);

        // close the ZipOutputStream
        zout.close();

        logger.info("Zip file has been created!");

    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }

}

From source file:co.cask.hydrator.transforms.Compressor.java

public static byte[] compressZIP(byte[] input) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ZipOutputStream zip = new ZipOutputStream(out);
    zip.write(input, 0, input.length);//  w ww  .jav  a 2  s  .co m
    zip.close();
    return out.toByteArray();
}

From source file:com.ikanow.aleph2.analytics.spark.utils.SparkPyTechnologyUtils.java

/** Create a zip containing the Aleph2 driver
 * @param bucket//  w ww  . j  a  v a 2s .c  o m
 * @param job
 * @throws IOException
 */
public static String writeAleph2DriverZip(final String signature) throws IOException {
    final String tmp_dir = System.getProperty("java.io.tmpdir");
    final String filename = tmp_dir + "/aleph2_driver_py_" + signature + ".zip";

    final InputStream io_stream = Thread.currentThread().getContextClassLoader()
            .getResourceAsStream("aleph2_driver.py");
    final FileOutputStream fout = new FileOutputStream(filename);
    final ZipOutputStream zout = new ZipOutputStream(fout);
    final ZipEntry ze = new ZipEntry("aleph2_driver.py");
    zout.putNextEntry(ze);
    zout.write(IOUtils.toString(io_stream).getBytes());
    zout.closeEntry();
    zout.close();

    return filename;
}

From source file:com.isomorphic.maven.util.ArchiveUtils.java

/**
 * Builds a ZIP file from the contents of a directory on the filesystem (recursively).
 * //from   w  w w.j a  v a  2  s.  co m
 * @see http://stackoverflow.com/questions/1281229/how-to-use-jaroutputstream-to-create-a-jar-file
 * 
 * @param directory the directory containing the content to be xzipped up
 * @param output the zip file to be written to
 * @throws IOException
 */
public static void zip(File directory, File output) throws IOException {
    output.getParentFile().mkdirs();
    ZipOutputStream target = new ZipOutputStream(new FileOutputStream(output));
    zip(directory, directory, target);
    target.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   w w  w  . j  a va2  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();
}

From source file:apim.restful.exportimport.utils.ArchiveGenerator.java

public static void writeZipFile(File directoryToZip, List<File> fileList) {

    try {// www  . j a  va2s.co m
        FileOutputStream fos = new FileOutputStream(directoryToZip.getPath() + ".zip");
        ZipOutputStream zos = new ZipOutputStream(fos);

        for (File file : fileList) {
            if (!file.isDirectory()) { // we only zip files, not directories
                addToZip(directoryToZip, file, zos);
            }
        }

        zos.close();
        fos.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}