Here you can find the source of zip(byte[] bytes)
public static byte[] zip(byte[] bytes) 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 { /**//from w ww. j a va 2s. c om * Compresses the given byte array using the standard Java deflater (which * uses the zlib compression library internally). */ public static byte[] zip(byte[] bytes) throws IOException { if (bytes == null) return null; if (bytes.length == 0) return new byte[0]; Deflater deflater = new Deflater(); deflater.setInput(bytes); ByteArrayOutputStream out = new ByteArrayOutputStream(bytes.length); deflater.finish(); byte[] buffer = new byte[1024]; while (!deflater.finished()) { int count = deflater.deflate(buffer); out.write(buffer, 0, count); } out.close(); return out.toByteArray(); } }