Java Uncompress Byte Array unZip(byte[] input)

Here you can find the source of unZip(byte[] input)

Description

un Zip

License

Apache License

Parameter

Parameter Description
input The zip data

Exception

Parameter Description
UnsupportedEncodingException The Character Encoding is not supported.

Return

The unzip data

Declaration

public static String unZip(byte[] input) throws UnsupportedEncodingException, IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.zip.*;

public class Main {
    public static final String CHARACTER_ENCODING_UTF_8 = "UTF-8";

    /**/*from  w w w  .  j  ava 2 s  .  c  o m*/
     *
     * @param input The zip data
     * @return The unzip data
     * @throws UnsupportedEncodingException The Character Encoding is not supported.
     */
    public static String unZip(byte[] input) throws UnsupportedEncodingException, IOException {

        ByteArrayInputStream inputStream = new ByteArrayInputStream(input);

        InflaterInputStream in = new InflaterInputStream(inputStream);
        ByteArrayOutputStream bout = new ByteArrayOutputStream(512);

        byte[] buffer = new byte[2048];
        int len = 0;
        while ((len = in.read(buffer)) > 0) {
            bout.write(buffer, 0, len);
        }
        in.close();
        bout.close();
        return bout.toString(CHARACTER_ENCODING_UTF_8);

    }
}

Related

  1. unzip(byte[] data)
  2. unZip(byte[] data)
  3. unzip(byte[] data)
  4. unzip(byte[] datas)
  5. unzip(byte[] in)
  6. unzip(byte[] output)
  7. unzip(byte[] src)
  8. unzip(byte[] zipData, File directory)
  9. unZip(byte[] zipFile)