Here you can find the source of compress(byte[] paramArrayOfByte)
public static byte[] compress(byte[] paramArrayOfByte) throws Exception
//package com.java2s; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.util.zip.GZIPOutputStream; public class Main { public static String compress(String paramString) throws Exception { return new String(compress(paramString.getBytes("utf-8")), "utf-8"); }/* ww w . jav a2 s .c o m*/ public static byte[] compress(byte[] paramArrayOfByte) throws Exception { ByteArrayInputStream localByteArrayInputStream = new ByteArrayInputStream( paramArrayOfByte); ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream(); GZIPOutputStream localGZIPOutputStream = new GZIPOutputStream( localByteArrayOutputStream); byte[] arrayOfByte = new byte[1024]; for (;;) { int i = localByteArrayInputStream.read(arrayOfByte, 0, 1024); if (i == -1) { localGZIPOutputStream.flush(); localGZIPOutputStream.finish(); localGZIPOutputStream.close(); return localByteArrayOutputStream.toByteArray(); } localGZIPOutputStream.write(arrayOfByte, 0, i); } } }