Example usage for java.util.zip ZipOutputStream write

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

Introduction

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

Prototype

public void write(int b) throws IOException 

Source Link

Document

Writes a byte to the compressed output stream.

Usage

From source file:ee.ria.xroad.common.messagelog.archive.LogArchiveCache.java

private void addLinkingInfoToArchive(ZipOutputStream zipOut) throws IOException {
    ZipEntry linkingInfoEntry = new ZipEntry("linkinginfo");

    zipOut.putNextEntry(linkingInfoEntry);
    zipOut.write(linkingInfoBuilder.build());
    zipOut.closeEntry();/*w w  w  .j  a va  2  s . c om*/

    linkingInfoBuilder.afterArchiveCreated();
}

From source file:com.genericworkflownodes.knime.nodes.io.outputfile.OutputFileNodeModel.java

/**
 * {@inheritDoc}/*w w  w.  ja  v a2  s  .  c  o m*/
 */
@Override
protected void saveInternals(final File internDir, final ExecutionMonitor exec)
        throws IOException, CanceledExecutionException {
    ZipOutputStream out = new ZipOutputStream(new FileOutputStream(new File(internDir, "loadeddata")));
    ZipEntry entry = new ZipEntry("rawdata.bin");
    out.putNextEntry(entry);
    out.write(data.getBytes());
    out.close();
}

From source file:com.jbrisbin.vpc.jobsched.batch.BatchMessageConverter.java

public Message toMessage(Object object, MessageProperties props) throws MessageConversionException {
    if (object instanceof BatchMessage) {
        BatchMessage batch = (BatchMessage) object;
        props.setCorrelationId(batch.getId().getBytes());
        props.setContentType("application/zip");

        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        ZipOutputStream zout = new ZipOutputStream(bout);
        for (Map.Entry<String, String> msg : batch.getMessages().entrySet()) {
            ZipEntry zentry = new ZipEntry(msg.getKey());
            try {
                zout.putNextEntry(zentry);
                zout.write(msg.getValue().getBytes());
                zout.closeEntry();//ww w .j  a  va 2s  . c  om
            } catch (IOException e) {
                throw new MessageConversionException(e.getMessage(), e);
            }
        }

        try {
            zout.flush();
            zout.close();
        } catch (IOException e) {
            throw new MessageConversionException(e.getMessage(), e);
        }

        return new Message(bout.toByteArray(), props);
    } else {
        throw new MessageConversionException(
                "Cannot convert object " + String.valueOf(object) + " using " + getClass().toString());
    }
}

From source file:org.activiti.designer.kickstart.eclipse.sync.SyncUtil.java

protected static void zipDirectory(final ZipOutputStream out, final File base,
        final String absoluteDirPathToStrip) throws Exception {
    File[] reportFiles = base.listFiles();
    for (final File file : reportFiles) {
        if (file.isDirectory()) {
            zipDirectory(out, file, absoluteDirPathToStrip);
            continue;
        }/* w  w w  .  j  a va 2s. co  m*/
        String entryName = StringUtils.removeStart(file.getAbsolutePath(), absoluteDirPathToStrip);
        entryName = backlashReplace(entryName);
        ZipEntry entry = new ZipEntry(entryName);
        out.putNextEntry(entry);
        if (file.isFile()) {
            FileInputStream fin = new FileInputStream(file);
            byte[] fileContent = new byte[(int) file.length()];
            fin.read(fileContent);
            out.write(fileContent);
            fin.close();
        }
        out.closeEntry();
    }
}

From source file:com.coinblesk.client.backup.BackupDialogFragment.java

private void addZipEntry(String filename, byte[] data, ZipOutputStream zos) throws IOException {
    ZipEntry entry = new ZipEntry(filename);
    zos.putNextEntry(entry);/* w  w  w.  j a  v  a 2 s.c  o m*/
    zos.write(data);
    zos.closeEntry();
    zos.flush();
}

From source file:com.eviware.soapui.impl.wsdl.support.FileAttachment.java

public void setData(byte[] data) {
    try {//from   ww  w . j a  va2  s.c  om
        // write attachment-data to tempfile
        ByteArrayOutputStream tempData = new ByteArrayOutputStream();
        ZipOutputStream out = new ZipOutputStream(tempData);
        out.putNextEntry(new ZipEntry(config.getName()));
        config.setSize(data.length);
        out.write(data);
        out.closeEntry();
        out.finish();
        out.close();
        config.setData(tempData.toByteArray());
    } catch (Exception e) {
        SoapUI.logError(e);
    }
}

From source file:ZipTransformTest.java

public void testStreamTransformerIdentity() throws IOException {
    final String name = "foo";
    final byte[] contents = "bar".getBytes();

    File file1 = File.createTempFile("temp", null);
    File file2 = File.createTempFile("temp", null);
    try {//from w w w . ja va2s.co  m
        // Create the ZIP file
        ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(file1));
        try {
            zos.putNextEntry(new ZipEntry(name));
            zos.write(contents);
            zos.closeEntry();
        } finally {
            IOUtils.closeQuietly(zos);
        }

        // Transform the ZIP file
        ZipUtil.transformEntry(file1, name, new StreamZipEntryTransformer() {
            protected void transform(ZipEntry zipEntry, InputStream in, OutputStream out) throws IOException {
                IOUtils.copy(in, out);
            }
        }, file2);

        // Test the ZipUtil
        byte[] actual = ZipUtil.unpackEntry(file2, name);
        assertNotNull(actual);
        assertEquals(new String(contents), new String(actual));
    } finally {
        FileUtils.deleteQuietly(file1);
        FileUtils.deleteQuietly(file2);
    }
}

From source file:ZipTransformTest.java

public void testByteArrayTransformer() throws IOException {
    final String name = "foo";
    final byte[] contents = "bar".getBytes();

    File file1 = File.createTempFile("temp", null);
    File file2 = File.createTempFile("temp", null);
    try {//from   w  ww .ja v a  2  s . c om
        // Create the ZIP file
        ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(file1));
        try {
            zos.putNextEntry(new ZipEntry(name));
            zos.write(contents);
            zos.closeEntry();
        } finally {
            IOUtils.closeQuietly(zos);
        }

        // Transform the ZIP file
        ZipUtil.transformEntry(file1, name, new ByteArrayZipEntryTransformer() {
            protected byte[] transform(ZipEntry zipEntry, byte[] input) throws IOException {
                String s = new String(input);
                assertEquals(new String(contents), s);
                return s.toUpperCase().getBytes();
            }
        }, file2);

        // Test the ZipUtil
        byte[] actual = ZipUtil.unpackEntry(file2, name);
        assertNotNull(actual);
        assertEquals(new String(contents).toUpperCase(), new String(actual));
    } finally {
        FileUtils.deleteQuietly(file1);
        FileUtils.deleteQuietly(file2);
    }
}

From source file:ZipTransformTest.java

public void testStreamTransformer() throws IOException {
    final String name = "foo";
    final byte[] contents = "bar".getBytes();
    final byte[] transformed = "cbs".getBytes();

    File file1 = File.createTempFile("temp", null);
    File file2 = File.createTempFile("temp", null);
    try {/*from www  . j  a  v a  2  s . c o m*/
        // Create the ZIP file
        ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(file1));
        try {
            zos.putNextEntry(new ZipEntry(name));
            zos.write(contents);
            zos.closeEntry();
        } finally {
            IOUtils.closeQuietly(zos);
        }

        // Transform the ZIP file
        ZipUtil.transformEntry(file1, name, new StreamZipEntryTransformer() {
            protected void transform(ZipEntry zipEntry, InputStream in, OutputStream out) throws IOException {
                int b;
                while ((b = in.read()) != -1)
                    out.write(b + 1);
            }
        }, file2);

        // Test the ZipUtil
        byte[] actual = ZipUtil.unpackEntry(file2, name);
        assertNotNull(actual);
        assertEquals(new String(transformed), new String(actual));
    } finally {
        FileUtils.deleteQuietly(file1);
        FileUtils.deleteQuietly(file2);
    }
}

From source file:ZipTransformTest.java

public void testStringZipEntryTransformerInStream() throws IOException {
    final String name = "foo";
    String FILE_CONTENTS = "bar";
    final byte[] contents = FILE_CONTENTS.getBytes();

    File file1 = File.createTempFile("temp", null);
    File file2 = File.createTempFile("temp", null);
    try {/* ww w  .  j  a va  2s. com*/
        // Create the ZIP file
        ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(file1));
        try {
            zos.putNextEntry(new ZipEntry(name));
            zos.write(contents);
            zos.closeEntry();
        } finally {
            IOUtils.closeQuietly(zos);
        }

        // Transform the ZIP file
        FileInputStream in = null;
        FileOutputStream out = null;
        try {
            in = new FileInputStream(file1);
            out = new FileOutputStream(file2);

            ZipUtil.transformEntry(in, name, new StringZipEntryTransformer("UTF-8") {
                protected String transform(ZipEntry zipEntry, String input) throws IOException {
                    return input.toUpperCase();
                }
            }, out);
        } finally {
            IOUtils.closeQuietly(in);
            IOUtils.closeQuietly(out);
        }

        // Test the ZipUtil
        byte[] actual = ZipUtil.unpackEntry(file2, name);
        assertEquals(FILE_CONTENTS.toUpperCase(), new String(actual));
    } finally {
        FileUtils.deleteQuietly(file1);
        FileUtils.deleteQuietly(file2);
    }
}