Java GZIPInputStream Create getGZIPDecompressStream(byte[] buffer)

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

Description

Create and return an InputStream that will read the given byte[] and decompress it as bytes are read from the stream.

License

Apache License

Parameter

Parameter Description
buffer A byte[] containing a GZIP-compressed value.

Exception

Parameter Description
IOExceptionIf an error occurs creating the GZIPInputStream (e.g., thebyte[] value is not a valid GZIP-compressed message).

Return

An InputStream that will stream the decompressed value as bytes as read.

Declaration

public static InputStream getGZIPDecompressStream(byte[] buffer) throws IOException 

Method Source Code


//package com.java2s;
/*//from  w w  w . ja  v  a2  s .  c  o  m
 * Copyright (C) 2014 Dell, 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.IOException;
import java.io.InputStream;

import java.util.zip.GZIPInputStream;

public class Main {
    /**
     * Create and return an InputStream that will read the given byte[] and decompress it
     * as bytes are read from the stream. Reading the byte[] as a decompression stream
     * saves memory when the array is large.
     * 
     * @param buffer        A byte[] containing a GZIP-compressed value.
     * @return              An InputStream that will stream the decompressed value as
     *                      bytes as read.
     * @throws IOException  If an error occurs creating the GZIPInputStream (e.g., the
     *                      byte[] value is not a valid GZIP-compressed message).
     */
    public static InputStream getGZIPDecompressStream(byte[] buffer) throws IOException {
        ByteArrayInputStream bytesIn = new ByteArrayInputStream(buffer);
        GZIPInputStream gzipIn = new GZIPInputStream(bytesIn);
        return gzipIn;
    }
}

Related

  1. getGzipInputStream(File file)
  2. getGZipInputStream(InputStream in)