Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.io.*;

import java.util.zip.GZIPInputStream;

public class Main {
    protected static final int ONE_MB = 1 << 20;

    protected static ByteArrayOutputStream inflate(final FileInputStream pInputStream) throws IOException {
        final ByteArrayOutputStream uncompressed = new ByteArrayOutputStream(ONE_MB);
        final GZIPInputStream zin = new GZIPInputStream(pInputStream);

        int read;
        final byte[] buf = new byte[ONE_MB];
        while ((read = zin.read(buf)) != -1) {
            uncompressed.write(buf, 0, read);
        }

        return uncompressed;
    }

    protected static ByteArrayOutputStream inflate(final ByteArrayOutputStream pOutCompressed) throws IOException {
        final ByteArrayOutputStream uncompressed = new ByteArrayOutputStream(ONE_MB);
        final GZIPInputStream zin = new GZIPInputStream(new ByteArrayInputStream(pOutCompressed.toByteArray()));

        int read;
        final byte[] buf = new byte[ONE_MB];
        while ((read = zin.read(buf)) != -1) {
            uncompressed.write(buf, 0, read);
        }

        return uncompressed;
    }
}