Here you can find the source of zip(byte[] data)
public static byte[] zip(byte[] data)
//package com.java2s; //License from project: Apache License import java.io.ByteArrayOutputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class Main { public static byte[] zip(byte[] data) { byte[] b = null; try {/*ww w .ja va 2 s. c om*/ ByteArrayOutputStream bos = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(bos); ZipEntry entry = new ZipEntry("zip"); entry.setSize(data.length); zip.putNextEntry(entry); zip.write(data); zip.closeEntry(); zip.close(); b = bos.toByteArray(); bos.close(); } catch (Exception ex) { ex.printStackTrace(); } return b; } }