Here you can find the source of zip(String str)
public static final String zip(String str)
//package com.java2s; //License from project: Apache License import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class Main { public static final String zip(String str) { if (str == null) return null; byte[] compressed; ByteArrayOutputStream out = null; ZipOutputStream zout = null; String compressedStr = null; try {/*from w ww .ja v a 2 s . co m*/ out = new ByteArrayOutputStream(); zout = new ZipOutputStream(out); zout.putNextEntry(new ZipEntry("0")); zout.write(str.getBytes()); zout.closeEntry(); compressed = out.toByteArray(); compressedStr = new sun.misc.BASE64Encoder().encodeBuffer(compressed); } catch (IOException e) { compressed = null; } finally { if (zout != null) { try { zout.close(); } catch (IOException e) { } } if (out != null) { try { out.close(); } catch (IOException e) { } } } return compressedStr; } }