Java Unzip ZipFile unzip(byte[] zippedBytes)

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

Description

unzip

License

Open Source License

Declaration

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

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.*;
import java.nio.charset.Charset;
import java.util.zip.GZIPInputStream;

public class Main {
    public static byte[] unzip(byte[] zippedBytes) throws IOException {
        int sChunk = 8192;

        ByteArrayInputStream in = new ByteArrayInputStream(zippedBytes);
        GZIPInputStream zipin = new GZIPInputStream(in);
        byte[] buffer = new byte[sChunk];
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        int length;
        while ((length = zipin.read(buffer, 0, sChunk)) != -1)
            out.write(buffer, 0, length);
        out.close();//  w ww . j  a va  2 s  . c om
        zipin.close();
        in.close();

        return out.toByteArray();
    }

    public static String unzip(byte[] zippedBytes, Charset charset) throws IOException {
        return new String(unzip(zippedBytes), charset);
    }
}

Related

  1. unzip(File srcFile, File toDir)
  2. unzip(final File zip, final File patchDir)
  3. unzip(final File zipFile, final String suffix)
  4. unzip(ZipEntry entry, ZipFile zipfile, File explodedDir)