Java GZip Read getGZippedContent(byte[] content)

Here you can find the source of getGZippedContent(byte[] content)

Description

get G Zipped Content

License

MIT License

Declaration

public static byte[] getGZippedContent(byte[] content) throws IOException 

Method Source Code


//package com.java2s;
/*/*  w  ww .j  av  a  2  s .c o m*/
 * Protorabbit
 *
 * Copyright (c) 2009 Greg Murray (protorabbit.org)
 * 
 * Licensed under the MIT License:
 * 
 *  http://www.opensource.org/licenses/mit-license.php
 *
 */

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

import java.util.zip.GZIPOutputStream;

public class Main {
    public static byte[] getGZippedContent(byte[] content) throws IOException {
        byte[] gzippedContent = null;
        if (content != null) {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ByteArrayInputStream bis = new ByteArrayInputStream(content);
            GZIPOutputStream out = new GZIPOutputStream(bos);
            byte[] buffer = new byte[1024];
            int read;
            while ((read = bis.read(buffer)) > 0) {
                out.write(buffer, 0, read);
            }
            bis.close();
            out.finish();
            out.close();
            gzippedContent = bos.toByteArray();
        }
        return gzippedContent;
    }
}

Related

  1. getGzipByteArrayOutputStream(String domJson)
  2. getGZIPContents(File f)
  3. getGzipExpandedBytes(File file)
  4. getGzippedBytesAsString(byte[] bytes)