Java Decompress Byte Array decompress(byte[] in)

Here you can find the source of decompress(byte[] in)

Description

decompress

License

Open Source License

Declaration

public static byte[] decompress(byte[] in) 

Method Source Code

//package com.java2s;
/**/*from  w  ww.  ja va2s .  co m*/
 * (C) 2007-2010 Taobao Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 */

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

import java.util.zip.GZIPInputStream;

public class Main {
    public static byte[] decompress(byte[] in) {
        ByteArrayOutputStream bos = null;

        if (in != null) {
            ByteArrayInputStream bis = new ByteArrayInputStream(in);

            bos = new ByteArrayOutputStream();

            GZIPInputStream gis = null;

            try {
                gis = new GZIPInputStream(bis);

                byte[] buf = new byte[8192];
                int r = -1;

                while ((r = gis.read(buf)) > 0) {
                    bos.write(buf, 0, r);
                }
            } catch (IOException e) {
                bos = null;
                throw new RuntimeException(e);
            } finally {
                try {
                    gis.close();
                    bos.close();
                } catch (Exception e) {
                }
            }
        }

        return (bos == null) ? null : bos.toByteArray();
    }
}

Related

  1. decompress(byte[] data)
  2. decompress(byte[] data)
  3. decompress(byte[] data, int off, int len)
  4. decompress(byte[] data, int offset, int length)
  5. decompress(byte[] gzipped)
  6. decompress(byte[] input)
  7. decompress(byte[] source)
  8. decompress(byte[] source)
  9. decompress(byte[] src, Inflater decompresser, int compressCycleSize)