Java Uncompress Byte Array unzip(byte[] bytes, String encoding)

Here you can find the source of unzip(byte[] bytes, String encoding)

Description

unzip

License

Open Source License

Declaration

public static String unzip(byte[] bytes, String encoding) 

Method Source Code


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

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

public class Main {
    public static String unzip(byte[] bytes, String encoding) {
        if (bytes == null) {
            return null;
        } else if (bytes.length == 0) {
            return "";
        }/*from ww w  . j  ava  2  s .com*/
        try (ByteArrayInputStream input = new ByteArrayInputStream(bytes);
                GZIPInputStream gin = new GZIPInputStream(input);
                ByteArrayOutputStream out = new ByteArrayOutputStream();) {
            byte[] buffer = new byte[1024 * 8];
            int n;
            while ((n = gin.read(buffer)) >= 0) {
                out.write(buffer, 0, n);
            }
            out.flush();
            return out.toString("UTF-8");
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. unzip(byte zipData[])
  2. unzip(byte[] blob)
  3. unzip(byte[] bytes)
  4. unzip(byte[] bytes)
  5. unzip(byte[] bytes)
  6. unzip(byte[] compressedByte)
  7. unzip(byte[] compressedData)
  8. unzip(byte[] content)
  9. unzip(byte[] content)