Here you can find the source of deflate(byte[] data)
public static byte[] deflate(byte[] data) throws IOException
//package com.java2s; // License: http://www.gnu.org/software/classpath/license.html import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.zip.Deflater; public class Main { public static byte[] deflate(byte[] data) throws IOException { try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { Deflater deflater = new Deflater(); try { deflater.setInput(data); deflater.finish();//from ww w .j av a 2 s . c o m byte[] buffer = new byte[1024]; while (!deflater.finished()) { int count = deflater.deflate(buffer); out.write(buffer, 0, count); } return out.toByteArray(); } finally { deflater.end(); } } } }