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:edu.isi.wings.portal.classes.StorageHandler.java

private static void streamDirectory(File directory, OutputStream os) {
    try {/*w  ww .ja v a 2s .c o  m*/
        // Start the ZipStream reader. Whatever is read is streamed to response
        PipedInputStream pis = new PipedInputStream(2048);
        ZipStreamer pipestreamer = new ZipStreamer(pis, os);
        pipestreamer.start();

        // Start Zipping folder and piping to the ZipStream reader
        PipedOutputStream pos = new PipedOutputStream(pis);
        ZipOutputStream zos = new ZipOutputStream(pos);
        StorageHandler.zipAndStream(directory, zos, directory.getName() + "/");
        zos.flush();
        zos.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:es.caib.sgtsic.util.Zips.java

public static DataHandler generateZip(Map<String, DataHandler> documents) throws IOException {

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ZipOutputStream zip = new ZipOutputStream(baos);

    for (String key : documents.keySet()) {

        InputStream is = new ByteArrayInputStream(DataHandlers.dataHandlerToByteArray(documents.get(key)));
        ZipEntry zipEntry = new ZipEntry(key);
        zip.putNextEntry(zipEntry);/*from   w w  w  .j av a2s .c o m*/
        IOUtils.copy(is, zip);
        zip.closeEntry();
        is.close();
    }

    zip.close();
    baos.close();

    return DataHandlers.byteArrayToDataHandler(baos.toByteArray(), "application/zip");

}

From source file:nz.ac.otago.psyanlab.common.util.FileUtils.java

/**
 * Compress a working directory to some destination.
 * //w  ww.ja va  2 s.  co  m
 * @param workingDir Directory whose contents will be archived.
 * @param destFile Destination file which will be written to.
 * @return Archive file written.
 * @throws FileNotFoundException
 * @throws IOException
 */
@Deprecated
public static File compress(File workingDir, File destFile) throws FileNotFoundException, IOException {
    ZipOutputStream out = new ZipOutputStream(new FileOutputStream(destFile));
    addFiles(workingDir, workingDir, out);
    out.close();

    return destFile;
}

From source file:ch.rgw.compress.CompEx.java

public static byte[] CompressZIP(InputStream in) throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    byte[] buf = new byte[8192];
    baos.write(buf, 0, 4); // Lnge des Originalstroms
    ZipOutputStream zo = new ZipOutputStream(baos);
    zo.putNextEntry(new ZipEntry("Data"));
    int l;//w  w w  .  j ava2 s .c o  m
    long total = 0;
    ;
    while ((l = in.read(buf, 0, buf.length)) != -1) {
        zo.write(buf, 0, l);
        total += l;
    }
    zo.close();
    byte[] ret = baos.toByteArray();
    // Die hchstwertigen 3 Bit als Typmarker setzen
    total &= 0x1fffffff;
    total |= ZIP;
    BinConverter.intToByteArray((int) total, ret, 0);
    return ret;
}

From source file:com.wisemapping.util.ZipUtils.java

public static byte[] bytesToZip(@NotNull final byte[] content) throws IOException {
    ZipOutputStream zip = null;
    final ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
    try {/*from  w w  w.j a v a 2 s .c om*/
        zip = new ZipOutputStream(byteArray);
        ZipEntry zEntry = new ZipEntry("content");
        zip.putNextEntry(zEntry);
        IOUtils.write(content, zip);
        zip.closeEntry();
    } finally {
        if (zip != null) {
            zip.flush();
            zip.close();
        }
    }

    return byteArray.toByteArray();
}

From source file:mpimp.assemblxweb.util.J5FileUtils.java

public static void zipDirectory(String dirPath, String targetPath) throws Exception {
    BufferedInputStream origin = null;
    FileOutputStream dest = new FileOutputStream(targetPath);
    ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(dest));
    out.setMethod(ZipOutputStream.DEFLATED);
    int BUFFER = 2048;
    byte data[] = new byte[BUFFER];
    zipDirectoryRecursively(dirPath, origin, BUFFER, out, data, new File(dirPath).getName());
    out.close();

}

From source file:Main.java

/**
 * Compress a folder and its contents.// ww w  .  j a  v a  2  s  . co m
 * 
 * @param srcFolder path to the folder to be compressed.
 * @param destZipFile path to the final output zip file.
 * @param addBaseFolder flag to decide whether to add also the provided base folder or not.
 * @throws IOException 
 */
static public void zipFolder(String srcFolder, String destZipFile, boolean addBaseFolder) throws IOException {
    if (new File(srcFolder).isDirectory()) {

        ZipOutputStream zip = null;
        FileOutputStream fileWriter = null;
        try {
            fileWriter = new FileOutputStream(destZipFile);
            zip = new ZipOutputStream(fileWriter);
            addFolderToZip("", srcFolder, zip, addBaseFolder); //$NON-NLS-1$
        } finally {
            if (zip != null) {
                zip.flush();
                zip.close();
            }
            if (fileWriter != null)
                fileWriter.close();
        }
    } else {
        throw new IOException(srcFolder + " is not a folder.");
    }
}

From source file:com.youTransactor.uCube.LogManager.java

public static void getLogs(OutputStream out) throws IOException {
    File logDir = context.getDir(LOG_DIR, Context.MODE_PRIVATE);

    if (logDir.listFiles().length > 0) {
        ZipOutputStream zout = new ZipOutputStream(out);

        for (File file : logDir.listFiles()) {
            ZipEntry entry = new ZipEntry(file.getName());
            zout.putNextEntry(entry);/*from  w  ww  .j av  a  2  s.co  m*/
            IOUtils.copy(new FileInputStream(file), zout);
            zout.closeEntry();
        }

        zout.close();
    }
}

From source file:fll.web.GatherBugReport.java

/**
 * Add the database to the zipfile.//ww  w.  j a v a2 s  .c  o m
 * 
 * @throws SQLException
 */
private static void addDatabase(final ZipOutputStream zipOut, final Connection connection,
        final Document challengeDocument) throws IOException, SQLException {

    ZipOutputStream dbZipOut = null;
    FileInputStream fis = null;
    try {
        final File temp = File.createTempFile("database", ".flldb");

        dbZipOut = new ZipOutputStream(new FileOutputStream(temp));
        DumpDB.dumpDatabase(dbZipOut, connection, challengeDocument);
        dbZipOut.close();

        zipOut.putNextEntry(new ZipEntry("database.flldb"));
        fis = new FileInputStream(temp);
        IOUtils.copy(fis, zipOut);
        fis.close();

        if (!temp.delete()) {
            temp.deleteOnExit();
        }

    } finally {
        IOUtils.closeQuietly(dbZipOut);
        IOUtils.closeQuietly(fis);
    }

}

From source file:com.recomdata.transmart.data.export.util.ZipUtil.java

/**
 * This method will zip a given folder./*from  w ww.ja  v a2  s . c  o  m*/
 * 
 * @param srcFolder
 * @param destZipFile
 * @throws Exception
 */
static public String zipFolder(String srcFolder, String destZipFile) throws Exception {
    File zipFile = null;
    ZipOutputStream zip = null;
    FileOutputStream fileWriter = null;

    zipFile = new File(destZipFile);
    if (zipFile.exists() && zipFile.isFile() && zipFile.delete()) {
        zipFile = new File(destZipFile);
    }

    fileWriter = new FileOutputStream(zipFile);
    zip = new ZipOutputStream(fileWriter);

    addFolderToZip("", srcFolder, zip);
    zip.flush();
    zip.close();

    return zipFile.getName();
}