Here you can find the source of compress(String string)
public static byte[] compress(String string)
//package com.java2s; //License from project: Apache License import java.io.ByteArrayOutputStream; import java.util.zip.GZIPOutputStream; import javax.xml.bind.DatatypeConverter; public class Main { public static byte[] compress(String string) { byte[] compressed = null; try {/*from w w w .j av a2s .c o m*/ ByteArrayOutputStream os = new ByteArrayOutputStream(string.length()); GZIPOutputStream gos = new GZIPOutputStream(os); gos.write(string.getBytes()); gos.close(); compressed = os.toByteArray(); os.close(); } catch (Exception e) { e.printStackTrace(); } return compressed; } public static byte[] toByteArray(String s) { return DatatypeConverter.parseHexBinary(s); } }