Java Decompress Byte Array decompress(byte[] data)

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

Description

decompress

License

Apache License

Parameter

Parameter Description
data a parameter

Declaration

public static final byte[] decompress(byte[] data) 

Method Source Code


//package com.java2s;
/*//from w  w  w.  j  a  v  a2s .co  m
 *   Copyright 2011 hexnova.com
 * 
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *    
 *   http://www.apache.org/licenses/LICENSE-2.0
 *    
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.GZIPInputStream;

public class Main {
    /**
     * @param data
     * @return
     */
    public static final byte[] decompress(byte[] data) {
        ByteArrayOutputStream buffer = null;
        GZIPInputStream gizpInputStream = null;
        try {
            buffer = new ByteArrayOutputStream();
            gizpInputStream = new GZIPInputStream(new ByteArrayInputStream(data));
            int n = -1;
            byte[] _buffer = new byte[1024 * 12];
            while (-1 != (n = gizpInputStream.read(_buffer))) {
                buffer.write(_buffer, 0, n);
            }
            gizpInputStream.close();
            buffer.close();
        } catch (IOException e) {
            throw new RuntimeException("Failed to GZip decompress data", e);
        }
        return buffer.toByteArray();
    }
}

Related

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