Example usage for java.util.zip ZipOutputStream putNextEntry

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

Introduction

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

Prototype

public void putNextEntry(ZipEntry e) throws IOException 

Source Link

Document

Begins writing a new ZIP file entry and positions the stream to the start of the entry data.

Usage

From source file:ee.ria.xroad.common.asic.AsicHelper.java

private static void addEntry(ZipOutputStream zip, String name, byte[] data) throws IOException {
    zip.putNextEntry(new ZipEntry(name));
    zip.write(data);//from w ww  . j  ava 2  s.  co m
}

From source file:eu.openanalytics.rsb.message.MultiFilesResult.java

/**
 * Zips all the files contained in a multifiles result except if the result is
 * not successful, in that case returns the first file (which should be the only
 * one and contain a plain text error message).
 * /*from www.j a v  a  2s. c om*/
 * @param result
 * @return
 * @throws FileNotFoundException
 * @throws IOException
 */
public static File zipResultFilesIfNotError(final MultiFilesResult result)
        throws FileNotFoundException, IOException {
    final File[] resultFiles = result.getPayload();

    if ((!result.isSuccess()) && (resultFiles.length == 1)) {
        return resultFiles[0];
    }

    final File resultZipFile = new File(result.getTemporaryDirectory(), result.getJobId() + ".zip");
    final ZipOutputStream resultZOS = new ZipOutputStream(new FileOutputStream(resultZipFile));

    for (final File resultFile : resultFiles) {
        resultZOS.putNextEntry(new ZipEntry(resultFile.getName()));

        final FileInputStream fis = new FileInputStream(resultFile);
        IOUtils.copy(fis, resultZOS);
        IOUtils.closeQuietly(fis);

        resultZOS.closeEntry();
    }

    IOUtils.closeQuietly(resultZOS);
    return resultZipFile;
}

From source file:ZipHandler.java

/**
 * makes a zip file named <xmlFileName> from <xmlURL> at path <zipURL>
 * @param zipURL// w w  w .  j a  v  a  2s.  co m
 * @param xmlURL
 * @param xmlFileName
 */

public static void makeStructZip(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);
    zos.closeEntry();
    fis.close();
    zos.close();
}

From source file:io.lavagna.service.LavagnaExporter.java

private static void writeEntry(String entryName, Object toSerialize, ZipOutputStream zf,
        OutputStreamWriter osw) {
    try {//from   www  .ja  v  a 2  s  . c om
        zf.putNextEntry(new ZipEntry(entryName));
        Json.GSON.toJson(toSerialize, osw);
        osw.flush();
        zf.flush();
        zf.closeEntry();
    } catch (IOException ioe) {
        throw new IllegalStateException("error while serializing entry " + entryName, ioe);
    }
}

From source file:es.gob.afirma.signers.ooxml.be.fedict.eid.applet.service.signer.ooxml.AbstractOOXMLSignatureService.java

private static void addOriginSigs(final ZipOutputStream zipOutputStream) throws IOException {
    zipOutputStream.putNextEntry(new ZipEntry("_xmlsignatures/origin.sigs")); //$NON-NLS-1$
}

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  va  2s .  co m
        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: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  a 2  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:ZipHandler.java

/**
 * makes a zip file named <xmlFileName> from <xmlURL> at path <zipURL>
 * @param zipURL/*w w  w .j  ava  2  s.c  om*/
 * @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();

}

From source file:Main.java

private static void compressFile(File file, ZipOutputStream out, String basedir) {
    if (!file.exists()) {
        return;//w ww  .j  a v  a 2 s .com
    }
    try {
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
        ZipEntry entry = new ZipEntry(basedir + file.getName());
        out.putNextEntry(entry);
        int count;
        byte data[] = new byte[BUFFER];
        while ((count = bis.read(data, 0, BUFFER)) != -1) {
            out.write(data, 0, count);
        }
        bis.close();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

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 v a 2 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();
}