Java Decompress Byte Array decompress(byte[] input)

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

Description

decompress

License

Apache License

Declaration

public final static byte[] decompress(byte[] input) throws IOException 

Method Source Code


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

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.DataFormatException;

import java.util.zip.Inflater;

public class Main {
    public final static int BUFFER_SIZE = 4092;

    public final static byte[] decompress(byte[] input) throws IOException {
        if (input == null || input.length == 0) {
            return input;
        }/*from   w w w.  ja  va 2 s  . co m*/
        Inflater inflator = new Inflater();
        inflator.setInput(input);
        ByteArrayOutputStream bin = new ByteArrayOutputStream(input.length);
        byte[] buf = new byte[BUFFER_SIZE];
        try {
            while (true) {
                int count = inflator.inflate(buf);
                if (count > 0) {
                    bin.write(buf, 0, count);
                } else if (count == 0 && inflator.finished()) {
                    break;
                } else {
                    throw new IOException("bad zip data, size:" + input.length);
                }
            }
        } catch (DataFormatException t) {
            throw new IOException(t);
        } finally {
            inflator.end();
        }
        return bin.toByteArray();
    }
}

Related

  1. decompress(byte[] data)
  2. decompress(byte[] data, int off, int len)
  3. decompress(byte[] data, int offset, int length)
  4. decompress(byte[] gzipped)
  5. decompress(byte[] in)
  6. decompress(byte[] source)
  7. decompress(byte[] source)
  8. decompress(byte[] src, Inflater decompresser, int compressCycleSize)
  9. decompress(byte[] str)