Example usage for java.util.zip GZIPOutputStream close

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

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Document

Writes remaining compressed data to the output stream and closes the underlying stream.

Usage

From source file:Main.java

static byte[] compress(byte[] decompressed) throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    GZIPOutputStream gzip = new GZIPOutputStream(bos);
    gzip.write(decompressed);//from w ww. ja  va2 s  .c om
    gzip.flush();
    gzip.close();
    bos.flush();
    bos.close();
    return bos.toByteArray();
}

From source file:Main.java

static public final byte[] gzipBytes(byte[] bytes) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    GZIPOutputStream gout = new GZIPOutputStream(out);
    try {//from  ww w. jav a 2  s  .  c  o m
        gout.write(bytes);
    } finally {
        gout.close();
    }
    return out.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();
    return baos.toByteArray();
}

From source file:Main.java

public static byte[] compress(byte[] content) throws IOException {
    ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
    byte[] byteMe = null;
    try {/* 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:ca.uhn.fhir.jpa.dao.GZipUtil.java

public static byte[] compress(String theEncoded) {
    try {//from  www .  ja  v a 2s.c  o  m
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        GZIPOutputStream gos = new GZIPOutputStream(os);
        IOUtils.write(theEncoded, gos, "UTF-8");
        gos.close();
        os.close();
        byte[] retVal = os.toByteArray();
        return retVal;
    } catch (IOException e) {
        throw new DataFormatException("Compress contents", e);
    }
}

From source file:Main.java

public static byte[] compressGzip(byte[] content) throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    GZIPOutputStream gos = new GZIPOutputStream(bos);
    try {//from w w  w  .j  ava 2s . co m
        gos.write(content);
        gos.flush();
    } finally {
        gos.close();
    }

    return bos.toByteArray();
}

From source file:Main.java

static byte[] getCompressedData(byte[] data) {
    ByteArrayOutputStream ser = new ByteArrayOutputStream();
    GZIPOutputStream gs;
    try {/*w w  w .  j  a va2  s .c  o m*/
        gs = new GZIPOutputStream(ser);
        gs.write(data);
        gs.close();
    } catch (IOException e) {
        throw new RuntimeException("Cannot compress data", e);
    }

    byte[] compressed = ser.toByteArray();
    return compressed;
}

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

public static byte[] compress(byte[] content) {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    try {/*from   w  ww.j a  v a2s  .  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 {//  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("Compression ratio %f\n", (1.0f * content.length / byteArrayOutputStream.size()));
    return byteArrayOutputStream.toByteArray();
}

From source file:org.projectforge.common.GZIPHelper.java

/**
 * @param str//from w w w . j a v a 2s . c  o m
 * @return Base64 encoded byte array.
 */
public static String compress(final String str) {
    if (str == null || str.length() == 0) {
        return str;
    }
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        final GZIPOutputStream gzip = new GZIPOutputStream(out);
        gzip.write(str.getBytes());
        gzip.close();
        return Base64Helper.encodeObject(out.toByteArray());
    } catch (final IOException ex) {
        log.error("Error while compressing string: " + ex.getMessage(), ex);
        return null;
    }
}