Here you can find the source of zipText(String text)
public static byte[] zipText(String text)
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayOutputStream; import java.util.zip.GZIPOutputStream; public class Main { public static byte[] zipText(String text) { byte[] ba = null; GZIPOutputStream gzos = null; ByteArrayOutputStream baos = null; try {// w ww . j a v a2 s . c om baos = new ByteArrayOutputStream(); if (baos != null) { gzos = new GZIPOutputStream(baos); byte[] stringAsBytes = (text).getBytes("UTF-8"); gzos.write(stringAsBytes, 0, stringAsBytes.length); gzos.finish(); baos.close(); ba = baos.toByteArray(); } } catch (Exception e) { e.printStackTrace(); } finally { if (baos != null) { try { gzos.close(); //baos.close(); } catch (Exception e1) { System.out .println("Exception while closing output stream"); } } } //System.out.println("Zipped\n"+baos.toString()); return ba; } }