Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import java.io.ByteArrayOutputStream;

import java.util.zip.Inflater;

public class Main {

    public static byte[] decompress(byte[] data, int off, int len) {

        byte[] output = null;

        Inflater decompresser = new Inflater();
        decompresser.reset();
        decompresser.setInput(data, off, len);

        ByteArrayOutputStream out = new ByteArrayOutputStream(data.length);
        try {
            byte[] result = new byte[1024];
            while (!decompresser.finished()) {
                int i = decompresser.inflate(result);
                out.write(result, 0, i);
            }
            output = out.toByteArray();
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            try {
                out.close();
            } catch (Exception e) {
            }
            decompresser.end();
        }
        return output;
    }
}