Java Decompress Byte Array decompress(byte[] compressedData)

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

Description

decompress

License

Apache License

Declaration

public static byte[] decompress(byte[] compressedData) throws 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.util.zip.GZIPInputStream;

public class Main {

    public static byte[] decompress(byte[] compressedData) throws IOException {
        ByteArrayOutputStream bytes = new ByteArrayOutputStream(compressedData.length);
        GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(compressedData));
        byte[] buffer = new byte[compressedData.length];

        while (true) {
            int bytesRead = in.read(buffer, 0, buffer.length);
            if (bytesRead < 0) {
                return bytes.toByteArray();
            }//from   w w w. ja v a 2  s  .c  o  m

            bytes.write(buffer, 0, bytesRead);
        }
    }
}

Related

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