Java Byte Array Uncompress uncompress(final byte[] buffer)

Here you can find the source of uncompress(final byte[] buffer)

Description

Uncompress a GZIP piece of content

License

LGPL

Parameter

Parameter Description
buffer a parameter

Return

the uncompressed content, or null if there was an error

Declaration

public static byte[] uncompress(final byte[] buffer) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

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

import java.io.IOException;

import java.util.zip.GZIPInputStream;

public class Main {
    /**//w ww  .j  a  va  2 s .  c  o  m
     * Uncompress a GZIP piece of content
     * 
     * @param buffer
     * @return the uncompressed content, or null if there was an error
     * @since 1.0.2
     */
    public static byte[] uncompress(final byte[] buffer) {
        try {
            final GZIPInputStream gzipis = new GZIPInputStream(new ByteArrayInputStream(buffer));

            final ByteArrayOutputStream baos = new ByteArrayOutputStream();

            final byte[] tmp = new byte[1024];
            int len;

            while ((len = gzipis.read(tmp)) > 0) {
                baos.write(tmp, 0, len);
            }

            baos.flush();

            return baos.toByteArray();
        } catch (final IOException ioe) {
            return null;
        }
    }
}

Related

  1. uncompress(byte[] b)
  2. uncompress(byte[] data)
  3. uncompress(byte[] gzData, String charset)
  4. uncompress(byte[] input, int uncompr_len)
  5. uncompress(final byte[] compressedData)
  6. uncompress(final byte[] src)
  7. uncompressByte(byte[] content)
  8. uncompressByteArray(byte[] ubytes, String type)