Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import java.util.zip.Inflater;

public class Main {
    public static byte[] decompress(byte[] data) {
        byte[] output = new byte[0];

        Inflater decompresser = new Inflater();
        decompresser.reset();
        decompresser.setInput(data);

        ByteArrayOutputStream bos = new ByteArrayOutputStream(2 * data.length);
        try {
            byte[] buf = new byte[1024];
            while (!decompresser.finished()) {
                int length = decompresser.inflate(buf);
                bos.write(buf, 0, length);
            }
            output = bos.toByteArray();
            bos.close();
        } catch (Exception e) {
            output = data;
            e.printStackTrace();
        }

        decompresser.end();
        return output;
    }
}