public static byte[] gzipCompress(byte[] data, int offset, int len) throws IOException
{
// assume 50% compression rate
ByteArrayOutputStream bytes = new ByteArrayOutputStream(len>>1);
OptimizedGZIPOutputStream out = new OptimizedGZIPOutputStream(bytes);
out.write(data, offset, len);
out.close();
return bytes.toByteArray();
}