Java Decompress Byte Array decompress(byte[] data)

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

Description

decompress

License

Open Source License

Declaration

public static byte[] decompress(byte[] data) 

Method Source Code


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

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import java.util.zip.InflaterOutputStream;

public class Main {
    public static byte[] decompress(byte[] data) {
        return decompress(data, 0, data.length);
    }/*from w w  w  .j a  va  2s.c o m*/

    public static byte[] decompress(byte[] data, int offset, int length) {
        try {
            ByteArrayOutputStream out = new ByteArrayOutputStream(length);
            InflaterOutputStream inflater = new InflaterOutputStream(out);
            inflater.write(data, offset, length);
            inflater.close();
            byte[] bytes = out.toByteArray();
            out.reset();
            InflaterOutputStream inflater2 = new InflaterOutputStream(out); //decompress a second time
            inflater2.write(bytes);
            inflater2.close();
            return out.toByteArray();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. decompress(byte[] compressed)
  2. decompress(byte[] compressed)
  3. decompress(byte[] compressedData)
  4. decompress(byte[] compressedData)
  5. decompress(byte[] compressedData, int off, int len)
  6. decompress(byte[] data)
  7. decompress(byte[] data)
  8. decompress(byte[] data)
  9. decompress(byte[] data)