Java GZip Read getGzipByteArrayOutputStream(String domJson)

Here you can find the source of getGzipByteArrayOutputStream(String domJson)

Description

Get gzip byte array output stream byte [ ].

License

Open Source License

Parameter

Parameter Description
domJson JSON as string to be gzipped

Return

byte[] of the gzipped string

Declaration

public static byte[] getGzipByteArrayOutputStream(String domJson) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.*;

import java.util.zip.GZIPOutputStream;

public class Main {
    /**//  w w w. j a  va 2  s .  c  o  m
     * Get gzip byte array output stream byte [ ].
     * @param domJson JSON as string to be gzipped
     * @return byte[] of the gzipped string
     */
    public static byte[] getGzipByteArrayOutputStream(String domJson) {
        ByteArrayOutputStream resultStream = new ByteArrayOutputStream();

        try {
            GZIPOutputStream gzip = new GZIPOutputStream(resultStream);
            gzip.write(domJson.getBytes());
            gzip.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return resultStream.toByteArray();
    }
}

Related

  1. getGZIPContents(File f)
  2. getGzipExpandedBytes(File file)
  3. getGzippedBytesAsString(byte[] bytes)
  4. getGZippedContent(byte[] content)