Java Gunzip File gunzip(InputStream packedData, OutputStream unpackedData)

Here you can find the source of gunzip(InputStream packedData, OutputStream unpackedData)

Description

gunzip

License

Open Source License

Declaration

public static void gunzip(InputStream packedData, OutputStream unpackedData) throws IOException 

Method Source Code

//package com.java2s;
/*/*from  w  ww.j a v a 2s. c  o m*/
 * The MIT License (MIT)
 * <p/>
 * Copyright (c) 2015 Maksym Dominichenko
 * <p/>
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * <p/>
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * <p/>
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

import java.io.*;

import java.util.zip.GZIPInputStream;

public class Main {
    private static final int BUFFER_SIZE = 4096;

    public static void gunzip(InputStream packedData, OutputStream unpackedData) throws IOException {
        copy(new GZIPInputStream(packedData), unpackedData);
    }

    public static void copy(InputStream sourceData, OutputStream targetData) throws IOException {
        final byte[] buffer = new byte[BUFFER_SIZE];
        for (int c = 0; c >= 0; c = sourceData.read(buffer, 0, buffer.length))
            if (c > 0)
                targetData.write(buffer, 0, c);
        targetData.flush();
    }
}

Related

  1. gunzip(File gzippedFile)
  2. gunzip(File gzippedFile, File destinationFile)
  3. gUnzip(File srcFile, File destFile)
  4. gunzip(String compressedStr)
  5. gunzip(String inFile, String outFile)
  6. gunzipFile(File baseDir, File gzFile)
  7. gunzipFile(File file_input, File dir_output)