Here you can find the source of gzip(String s)
public static byte[] gzip(String s) throws Exception
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayOutputStream; import java.io.OutputStreamWriter; import java.nio.charset.StandardCharsets; import java.util.zip.GZIPOutputStream; public class Main { public static byte[] gzip(String s) throws Exception { ByteArrayOutputStream bos = new ByteArrayOutputStream(); GZIPOutputStream gzip = new GZIPOutputStream(bos); OutputStreamWriter osw = new OutputStreamWriter(gzip, StandardCharsets.UTF_8); osw.write(s);// www . j av a 2s .c o m osw.close(); return bos.toByteArray(); } }