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.*;
import java.util.zip.*;

public class Main {
    public static byte[] compress(String str) throws Exception {
        if (str == null || str.length() == 0) {
            return null;
        }

        ByteArrayOutputStream obj = new ByteArrayOutputStream();
        GZIPOutputStream gzip = new GZIPOutputStream(obj);

        gzip.write(str.getBytes());
        gzip.close();

        byte[] compressed = obj.toByteArray();
        obj.close();

        return compressed;
    }
}