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.ByteArrayOutputStream;
import java.io.IOException;

import java.util.zip.GZIPOutputStream;

public class Main {
    public static byte[] compress(byte[] src) throws IOException {

        GZIPOutputStream gzip = null;
        ByteArrayOutputStream baos = null;
        try {
            baos = new ByteArrayOutputStream();

            gzip = new GZIPOutputStream(baos);
            gzip.write(src);
            gzip.finish();

            return baos.toByteArray();

        } finally {
            if (gzip != null) {
                gzip.close();
            }
            if (baos != null) {
                baos.close();
            }
        }
    }
}