Java Decompress Byte Array Decompress(byte[] bytes)

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

Description

Decompress

License

Open Source License

Declaration

public static String Decompress(byte[] bytes) throws Exception 

Method Source Code


//package com.java2s;
import java.io.ByteArrayOutputStream;

import java.util.zip.Inflater;

public class Main {
    public static String Decompress(byte[] bytes) throws Exception {
        Inflater decompressor = new Inflater();
        decompressor.setInput(bytes);//from  w ww .ja va2 s . co  m

        // Create an expandable byte array to hold the decompressed data
        ByteArrayOutputStream bos = new ByteArrayOutputStream(bytes.length);

        byte[] buffer = new byte[1024];
        try {
            while (true) {
                int count = decompressor.inflate(buffer);
                if (count > 0) {
                    bos.write(buffer, 0, count);
                } else if (count == 0 && decompressor.finished()) {
                    break;
                } else {
                    throw new RuntimeException("Bad zip data, size: " + bytes.length);
                }
            }
        } finally {
            decompressor.end();
        }

        bos.close();
        return bos.toString("UTF-16LE");
    }
}

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)
  7. decompress(byte[] bytes, int bufferSize)