Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import java.util.zip.InflaterInputStream;

public class Main {
    private static final int EXPECTED_COMPRESSION_RATIO = 5;

    public static byte[] inflate(byte[] in) throws IOException {
        return inflate(new ByteArrayInputStream(in), EXPECTED_COMPRESSION_RATIO * in.length);
    }

    public static byte[] inflate(InputStream in, int bufferSize) throws IOException {
        ByteArrayOutputStream outStream = new ByteArrayOutputStream(bufferSize);

        InflaterInputStream inStream = new InflaterInputStream(in);

        byte[] buf = new byte[4096];
        while (true) {
            int size = inStream.read(buf);
            if (size <= 0)
                break;
            outStream.write(buf, 0, size);
        }
        outStream.close();

        return outStream.toByteArray();
    }
}