Java tutorial
//package com.java2s; //License from project: BSD License import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.nio.charset.Charset; import java.util.zip.GZIPOutputStream; import com.amazonaws.util.IOUtils; public class Main { static private Charset utf8 = Charset.forName("UTF-8"); static public byte[] gzipString(String src, byte default_value[]) { if (src == null) return default_value; return gzip(src.getBytes(utf8), default_value); } static public byte[] gzip(byte src[], byte default_value[]) { try { if (src == null) return default_value; ByteArrayOutputStream out_raw = new ByteArrayOutputStream(); GZIPOutputStream out = new GZIPOutputStream(out_raw); ByteArrayInputStream in = new ByteArrayInputStream(src); IOUtils.copy(in, out); in.close(); out.close(); return out_raw.toByteArray(); } catch (Exception e) { return default_value; } } }