Here you can find the source of zip(String inputStr)
public static byte[] zip(String inputStr)
//package com.java2s; //License from project: Open Source License import java.io.UnsupportedEncodingException; import java.util.zip.Deflater; public class Main { public static byte[] zip(String inputStr) { byte[] input = null; try {/*from w ww . j a v a2s . c o m*/ input = inputStr.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { // cannot happen, because UTF-8 is always valid return null; } byte[] output = new byte[64 * 1000]; Deflater compresser = new Deflater(); compresser.setInput(input); compresser.finish(); int len = compresser.deflate(output); compresser.end(); byte[] shortOut = new byte[len]; System.arraycopy(output, 0, shortOut, 0, len); return shortOut; } }