Decompress a Byte Array in Java

Description

The following code shows how to decompress a Byte Array.

Example


/* w  w  w . ja va2  s. c o  m*/
import java.io.ByteArrayOutputStream;
import java.util.zip.Inflater;

public class Main {
  public static void main(String[] argv) throws Exception {
    byte[] compressedData = null;
    Inflater decompressor = new Inflater();
    decompressor.setInput(compressedData);
    ByteArrayOutputStream bos = new ByteArrayOutputStream(compressedData.length);
    byte[] buf = new byte[1024];
    while (!decompressor.finished()) {
      int count = decompressor.inflate(buf);
      bos.write(buf, 0, count);

    }
    bos.close();
    byte[] decompressedData = bos.toByteArray();

  }
}




















Home »
  Java Tutorial »
    I/O »




Binary File
Byte Array
CharSet
Checksum
Console
Create Copy Move Delete
Directory
Drive
Encode Decode
File Attribute
File Lock
File System
GZIP
Jar File
NIO Buffer
Path
Scanner
StreamTokenizer
Temporary File
Text File
Zip