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.GZIPOutputStream;

public class Main {
    public static byte[] compressInGzip(byte[] originalData) throws Exception {
        return compressInGzip(originalData, 0, originalData.length);
    }

    public static byte[] compressInGzip(byte[] originalData, int offset, int length) throws Exception {

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        GZIPOutputStream gzipOutStream = new GZIPOutputStream(bos);
        gzipOutStream.write(originalData, offset, length);
        gzipOutStream.finish();
        gzipOutStream.flush();
        gzipOutStream.close();
        byte[] compressData = bos.toByteArray();
        bos.close();

        return compressData;
    }
}