Here you can find the source of gzip(String str)
public static String gzip(String str) throws IOException
//package com.java2s; //License from project: Apache License import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.zip.GZIPOutputStream; public class Main { private static final Charset CHARSET_ZIP = StandardCharsets.ISO_8859_1; public static String gzip(String str) throws IOException { if (null == str || str.length() < 1) { return str; }/*from ww w .java 2 s . c o m*/ ByteArrayOutputStream out = new ByteArrayOutputStream(); try (GZIPOutputStream gzip = new GZIPOutputStream(out)) { gzip.write(str.getBytes()); } return out.toString(CHARSET_ZIP.name()); } }