Here you can find the source of deflate(byte[] data)
public static byte[] deflate(byte[] data)
//package com.java2s; import java.io.ByteArrayOutputStream; import java.util.zip.Deflater; public class Main { /**//ww w.j av a2 s. com * deflate compression * */ public static byte[] deflate(byte[] data) { Deflater compresser = new Deflater(); compresser.setLevel(Deflater.BEST_COMPRESSION); compresser.setInput(data); compresser.finish(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] bytes = new byte[1024]; compresser.deflate(bytes); while (!compresser.finished()) { bos.write(bytes, 0, compresser.deflate(bytes)); } bytes = bos.toByteArray(); return bytes; } }