Here you can find the source of toCompressData(Serializable o)
public static byte[] toCompressData(Serializable o) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; import java.util.zip.Deflater; import java.util.zip.DeflaterOutputStream; public class Main { /** Write the object to a compress byte[]. */ public static byte[] toCompressData(Serializable o) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); Deflater def = new Deflater(Deflater.BEST_COMPRESSION); DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(baos, def); ObjectOutputStream oos = new ObjectOutputStream(deflaterOutputStream); oos.writeObject(o);//w w w . j av a 2 s .c o m oos.close(); return baos.toByteArray(); } }