Java Decompress Byte Array decompress(byte[] bytes)

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

Description

Decompress byte array

License

Open Source License

Parameter

Parameter Description
bytes <code>byte</code> array to decompress

Exception

Parameter Description
DataFormatException if anything happens
IOException if anything happens

Return

decompressed byte array

Declaration

public static byte[] decompress(byte[] bytes) throws DataFormatException, IOException 

Method Source Code


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

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

import java.util.zip.Inflater;

public class Main {
    private static final Inflater inflater = new Inflater();

    /**/*from www.j  ava  2 s .  c o  m*/
     * Decompress <code>byte</code> array
     * @param bytes <code>byte</code> array to decompress
     * @return decompressed <code>byte</code> array
     * @throws DataFormatException if anything happens
     * @throws IOException if anything happens
     */
    public static byte[] decompress(byte[] bytes) throws DataFormatException, IOException {
        inflater.setInput(bytes);

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream(bytes.length);

        byte[] buffer = new byte[1024];
        while (!inflater.finished()) {
            int count = inflater.inflate(buffer);
            outputStream.write(buffer, 0, count);
        }
        outputStream.close();

        byte[] output = outputStream.toByteArray();
        inflater.reset();
        return output;
    }
}

Related

  1. decompress(byte[] byteArray)
  2. decompress(byte[] bytes)
  3. Decompress(byte[] bytes)
  4. decompress(byte[] bytes)
  5. decompress(byte[] bytes)
  6. decompress(byte[] bytes)