Example usage for java.util.zip GZIPOutputStream write

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

Introduction

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

Prototype

public void write(int b) throws IOException 

Source Link

Document

Writes a byte to the compressed output stream.

Usage

From source file:Main.java

public static byte[] doZip(byte[] data) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    java.util.zip.GZIPOutputStream gout = new GZIPOutputStream(out);
    gout.write(data);
    gout.close();/*from www.j a  v a2  s  . c om*/
    return out.toByteArray();
}

From source file:Main.java

public static byte[] gzipCompress(byte[] input) {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try {// ww w .j  a va2  s. c o m
        GZIPOutputStream os = new GZIPOutputStream(bos);
        os.write(input);
        os.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return bos.toByteArray();
}

From source file:com.mirth.connect.connectors.http.HttpUtil.java

public static byte[] compressGzip(String content, String charset) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    GZIPOutputStream gzos = new GZIPOutputStream(baos);
    gzos.write(content.getBytes(charset));
    gzos.close();//from w  w  w  .ja v a2s.c  o  m
    return baos.toByteArray();
}

From source file:Main.java

/**
 * GZip a given byte-array in-memory./*  w  w w .j  ava2 s.  c  om*/
 * 
 * @param bytes
 *            the uncompressed bytes
 * 
 * @return the GZipped byte stream
 * 
 * @throws IOException
 *             if something fails
 */
public static byte[] gzipByteArray(byte[] bytes) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream(bytes.length);

    GZIPOutputStream gzip = new GZIPOutputStream(baos);
    gzip.write(bytes);
    gzip.close();

    return baos.toByteArray();
}

From source file:Main.java

public static byte[] compress(byte[] content) throws IOException {
    ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
    byte[] byteMe = null;
    try {//from w w w.ja v a 2 s  .co  m
        GZIPOutputStream gzipOutputStream = new GZIPOutputStream(byteOut);
        gzipOutputStream.write(content);
        gzipOutputStream.close();
        byteMe = byteOut.toByteArray();
    } finally {
        byteOut.close();
    }
    return byteMe;
}

From source file:ByteUtils.java

public static byte[] packRaw(byte[] b) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    GZIPOutputStream zos = new GZIPOutputStream(baos);
    zos.write(b);
    zos.close();/*from  w w  w  . j  a  v  a 2s . c  o  m*/

    return baos.toByteArray();
}

From source file:com.giacomodrago.immediatecrypt.messagecipher.Compression.java

public static byte[] compress(byte[] plaintext) {
    try {/*from  ww  w. j  av  a2 s . co m*/
        ByteArrayOutputStream writer = new ByteArrayOutputStream();
        GZIPOutputStream gzipStream = new GZIPOutputStream(writer);
        gzipStream.write(plaintext);
        gzipStream.flush();
        gzipStream.close();
        writer.close();
        return writer.toByteArray();
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:org.openmrs.module.shr.contenthandler.api.ContentTest.java

private static byte[] compressGZip(String content) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    GZIPOutputStream gzipOut = new GZIPOutputStream(out);
    gzipOut.write(content.getBytes());
    IOUtils.closeQuietly(gzipOut);/*w w w  .  j  a  v  a  2s . co m*/
    return out.toByteArray();
}

From source file:org.eclipse.winery.accountability.blockchain.util.CompressionUtils.java

public static byte[] compress(byte[] content) {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    try {/*from  w w  w  .j  a  v  a 2  s  .co m*/
        GZIPOutputStream gzipOutputStream = new GZIPOutputStream(byteArrayOutputStream);
        gzipOutputStream.write(content);
        gzipOutputStream.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    System.out.printf("Compressiono %f\n", (1.0f * content.length / byteArrayOutputStream.size()));
    return byteArrayOutputStream.toByteArray();
}

From source file:tools.xor.util.JsonZip.java

public static byte[] compress(byte[] content) {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    try {/*from w  ww .  ja va  2s  .co m*/
        GZIPOutputStream gzipOutputStream = new GZIPOutputStream(byteArrayOutputStream);
        gzipOutputStream.write(content);
        gzipOutputStream.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    System.out.printf("Compression ratio %f\n", (1.0f * content.length / byteArrayOutputStream.size()));
    return byteArrayOutputStream.toByteArray();
}