Java Uncompress Byte Array unzip(byte[] data)

Here you can find the source of unzip(byte[] data)

Description

unzip

License

Open Source License

Declaration

public static byte[] unzip(byte[] data) throws IOException 

Method Source Code

//package com.java2s;
/***************************************************************************
 *   Filename: Util.java/* w ww. jav a 2  s.c om*/
 *   Author: artjom.lind@ut.ee
 ***************************************************************************
 *   Copyright (C) 2009 by Ulrich Norbisrath
 *   devel@mail.ulno.net
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Library General Public License as
 *   published by the Free Software Foundation; either version 2 of the
 *   License, or (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU Library General Public
 *   License along with this program; if not, write to the
 *   Free Software Foundation, Inc.,
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 ***************************************************************************
 *   Description:
 *   For handling the serialization and compression
 ***************************************************************************/

import java.io.ByteArrayInputStream;

import java.io.IOException;
import java.io.InputStream;

import java.util.ArrayList;
import java.util.List;
import java.util.zip.GZIPInputStream;

public class Main {
    public static byte[] unzip(byte[] data) throws IOException {
        InputStream is = new ByteArrayInputStream(data);
        GZIPInputStream gz = new GZIPInputStream(is);
        List<Byte> l = new ArrayList<Byte>();
        while (gz.available() != 0)
            l.add((byte) gz.read());
        // last byte is unnecessary (it is -1)
        byte[] uncmp = new byte[l.size() - 1];
        for (int i = 0; i < l.size() - 1; i++)
            uncmp[i] = l.get(i);
        return uncmp;
    }
}

Related

  1. unzip(byte[] content)
  2. unzip(byte[] content)
  3. unZip(byte[] contents)
  4. unzip(byte[] data)
  5. unZip(byte[] data)
  6. unzip(byte[] datas)
  7. unzip(byte[] in)
  8. unZip(byte[] input)
  9. unzip(byte[] output)