Here you can find the source of zip(byte[] source)
public static byte[] zip(byte[] source)
//package com.java2s; /**/*from w w w . j ava 2 s . co m*/ * Classe di utilita' per la serializzazione degli oggetti. * * <br><br>License: GNU General Public License<br> * * @author Pier Paolo Ciarravano * @version Vers. 0.98 (29/09/2009) */ import java.io.ByteArrayOutputStream; import java.util.zip.Deflater; public class Main { private static final int BUFFER_SIZE_FOR_ZIP = 1024; public static byte[] zip(byte[] source) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); Deflater deflater = new Deflater(); deflater.setInput(source); deflater.finish(); byte[] buffer = new byte[BUFFER_SIZE_FOR_ZIP]; int writeByte = 0; //int tot = 0; while ((writeByte = deflater.deflate(buffer)) != 0) { //tot += writeByte; //System.out.println(writeByte + " -> " + tot); baos.write(buffer, 0, writeByte); } deflater.end(); return baos.toByteArray(); } }