Java Uncompress Byte Array unzip(byte[] content)

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

Description

Method unzip

License

Open Source License

Parameter

Parameter Description
content byte[]

Exception

Parameter Description
IOException an exception

Return

String

Declaration

public static String unzip(byte[] content) throws IOException 

Method Source Code


//package com.java2s;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

import java.util.zip.InflaterInputStream;

public class Main {
    /**/*  w w w . jav  a2s  .  c om*/
     * Field BUF_LEN
     */
    private static int BUF_LEN = 1024;

    /**
     * Method unzip
     * @param content byte[]
     * @return String
     * @throws IOException
     */
    public static String unzip(byte[] content) throws IOException {
        return new String(inflate(content));
    }

    /**
     * Method inflate
     * @param input byte[]
     * @return byte[]
     * @throws IOException
     */
    public static byte[] inflate(byte[] input) throws IOException {
        ByteArrayInputStream bis = new ByteArrayInputStream(input);
        InflaterInputStream iis = new InflaterInputStream(bis);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        byte[] buffer = new byte[BUF_LEN];
        int bytesRead = iis.read(buffer);

        while (bytesRead > 0) {
            bos.write(buffer, 0, bytesRead);
            bytesRead = iis.read(buffer);
        }

        bos.flush();

        return bos.toByteArray();
    }
}

Related

  1. unzip(byte[] bytes)
  2. unzip(byte[] bytes, String encoding)
  3. unzip(byte[] compressedByte)
  4. unzip(byte[] compressedData)
  5. unzip(byte[] content)
  6. unZip(byte[] contents)
  7. unzip(byte[] data)
  8. unZip(byte[] data)
  9. unzip(byte[] data)