Compresses a byte array with gzip - Java File Path IO

Java examples for File Path IO:GZIP

Description

Compresses a byte array with gzip

Demo Code


//package com.java2s;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import java.util.zip.GZIPOutputStream;

public class Main {
    /**//from  ww w  .ja v  a2 s.com
     * Compresses a byte array
     */
    public static byte[] compress(byte[] theBytes) throws IOException {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        GZIPOutputStream gos = new GZIPOutputStream(bos);
        gos.write(theBytes);
        gos.close();
        return bos.toByteArray();
    }
}

Related Tutorials