Here you can find the source of gzip(byte[] data)
public static byte[] gzip(byte[] data) throws IOException
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class Main { public static byte[] gzip(byte[] data) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ZipEntry ze = new ZipEntry("servletservice"); ZipOutputStream zos = new ZipOutputStream(baos); zos.putNextEntry(ze);// ww w.ja v a 2s . c o m zos.write(data, 0, data.length); zos.close(); byte[] zipBytes = baos.toByteArray(); return zipBytes; } }