Here you can find the source of deflate(byte[] data)
public static byte[] deflate(byte[] data) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.zip.Deflater; public class Main { public static byte[] deflate(byte[] data) throws IOException { Deflater deflater = new Deflater(Deflater.DEFAULT_COMPRESSION, true); deflater.setInput(data);// w ww . j av a 2 s . c o m ByteArrayOutputStream outputStream = new ByteArrayOutputStream( data.length); deflater.finish(); byte[] buffer = new byte[1024]; while (!deflater.finished()) { int count = deflater.deflate(buffer); outputStream.write(buffer, 0, count); } outputStream.close(); byte[] output = outputStream.toByteArray(); deflater.end(); return output; } }