Java Gunzip Byte Array gunzip(byte[] data)

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

Description

Decompress a GZIP compressed byte array.

License

Apache License

Declaration

@SuppressWarnings("PMD.AssignmentInOperand")
static byte[] gunzip(byte[] data) throws IOException 

Method Source Code


//package com.java2s;
/*/*from  www. j a va  2  s .c  o m*/
 * Copyright 2014-2018 Netflix, Inc.
 *
 * 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.io.InputStream;

import java.util.zip.GZIPInputStream;

public class Main {
    /** Decompress a GZIP compressed byte array. */
    @SuppressWarnings("PMD.AssignmentInOperand")
    static byte[] gunzip(byte[] data) throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream(data.length * 10);
        try (InputStream in = new GZIPInputStream(new ByteArrayInputStream(data))) {
            byte[] buffer = new byte[4096];
            int length;
            while ((length = in.read(buffer)) > 0) {
                baos.write(buffer, 0, length);
            }
        }
        return baos.toByteArray();
    }
}

Related

  1. gunzip(byte[] bytes)
  2. gunzip(byte[] bytes)
  3. gunzip(byte[] bytes)
  4. gunzip(byte[] contentBytes)
  5. gunzip(byte[] data)
  6. gunzip(byte[] data)
  7. gunzip(byte[] in)
  8. gunzip(final byte[] b, final Class c)
  9. gunzip(final byte[] pInput)