Example usage for java.util.zip ZipOutputStream finish

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

Introduction

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

Prototype

public void finish() throws IOException 

Source Link

Document

Finishes writing the contents of the ZIP output stream without closing the underlying stream.

Usage

From source file:org.rhq.plugins.jmx.test.JMXPluginTest.java

private static File createCustomPluginFile() throws Exception {

    File plugin = new File("src/test/resources/custom-test-plugin.xml");
    File targetFile = new File(System.getProperty("java.io.tmpdir"), "custom-test-plugin.jar");
    targetFile.deleteOnExit();// ww  w  .  j  ava2s.c o m

    ZipOutputStream outputStream = new ZipOutputStream(new FileOutputStream(targetFile));
    ZipEntry metainf = new ZipEntry("META-INF");
    outputStream.putNextEntry(metainf);
    outputStream.closeEntry();

    ZipEntry pluginXml = new ZipEntry("META-INF/rhq-plugin.xml");
    outputStream.putNextEntry(pluginXml);
    FileInputStream fis = new FileInputStream(plugin);
    int bufferSize = 1024;
    BufferedInputStream bufferedInputStream = new BufferedInputStream(fis, bufferSize);
    int size;
    byte data[] = new byte[bufferSize];
    while ((size = bufferedInputStream.read(data, 0, bufferSize)) != -1) {
        outputStream.write(data, 0, size);
    }
    bufferedInputStream.close();
    outputStream.closeEntry();
    outputStream.flush();
    outputStream.finish();

    return targetFile;
}

From source file:com.googlecode.dex2jar.v3.Dex2jar.java

public void to(OutputStream os) throws IOException {
    ZipOutputStream zos = new ZipOutputStream(os);
    doTranslate(zos);/*  w  ww. jav a  2s  .  c o m*/
    zos.finish();
}

From source file:com.yunmel.syncretic.utils.io.IOUtils.java

/**
 * ?/*  w  w w.  j a  va 2s . c  o  m*/
 * 
 * @param files 
 * @param out ?
 * @throws java.io.IOException
 * @throws Exception
 */
public static void zipDownLoad(File file, HttpServletResponse response) throws IOException {

    ServletOutputStream out = response.getOutputStream();
    ZipOutputStream zipout = new ZipOutputStream(out);

    zipout.setLevel(1);
    // zipout.setEncoding("GBK");
    for (File f : file.listFiles()) {
        if (f.isFile()) {
            compressFile(f, f.getName(), zipout, "");
        } else {
            compressFolder(f, f.getName(), zipout, "");
        }
    }

    zipout.finish();
    zipout.flush();
}

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. j  a va  2s  .  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);
    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 ww  w  .j  a  v  a  2s .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);
    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  va2s.  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);
    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:org.orbeon.oxf.main.SecureResource.java

private void encrypt() {
    try {/*from   ww  w.ja v  a2 s  .  c om*/
        FileOutputStream archiveFile = new FileOutputStream(archiveName);

        ZipOutputStream zip = new ZipOutputStream(new CipherOutputStream(archiveFile,
                SecureUtils.getEncryptingCipher(SecureResourceManagerImpl.getPassword(), true)));
        File rr = new File(resourceRoot);
        archiveAndEncrypt(rr, zip);
        zip.finish();
        zip.close();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.drools.guvnor.server.files.RepositoryBackupServlet.java

private void processExportRepositoryDownload(HttpServletResponse res)
        throws RulesRepositoryException, IOException {
    log.debug("Exporting...");
    res.setContentType("application/zip");
    res.setHeader("Content-Disposition", "attachment; filename=repository_export.zip;");

    log.debug("Starting to process export");
    ZipOutputStream zout = new ZipOutputStream(res.getOutputStream());
    zout.putNextEntry(new ZipEntry("repository_export.xml"));
    fileManagerService.exportRulesRepository(zout);
    zout.closeEntry();//from  w ww .  j  av a  2 s . c o  m
    zout.finish();
    res.getOutputStream().flush();
    log.debug("Done exporting!");
}

From source file:gov.nih.nci.caarray.services.external.v1_0.grid.client.GridDataApiUtils.java

/**
 * {@inheritDoc}/*w  w w.  ja v  a 2  s .c om*/
 */
public void copyFileContentsZipToOutputStream(Iterable<CaArrayEntityReference> fileRefs, OutputStream ostream)
        throws InvalidReferenceException, DataTransferException, IOException {
    ZipOutputStream zos = new ZipOutputStream(ostream);
    for (CaArrayEntityReference fileRef : fileRefs) {
        TransferServiceContextReference transferRef = getFileContentsTransfer(fileRef, true);
        addToZip(transferRef, zos);
    }
    zos.finish();
}

From source file:gov.nih.nci.caarray.services.external.v1_0.data.JavaDataApiUtils.java

/**
 * {@inheritDoc}//from w w  w. ja  v  a2 s .  c o m
 */
public void copyFileContentsZipToOutputStream(Iterable<CaArrayEntityReference> fileRefs, OutputStream ostream)
        throws InvalidReferenceException, DataTransferException, IOException {
    ZipOutputStream zos = new ZipOutputStream(ostream);
    for (CaArrayEntityReference fileRef : fileRefs) {
        FileStreamableContents fsContents = dataService.streamFileContents(fileRef, true);
        zos.putNextEntry(new ZipEntry(fsContents.getMetadata().getName()));
        readFully(fsContents.getContentStream(), zos, true);
    }
    zos.finish();
}