Here you can find the source of compressToBase64(byte[] message)
public static String compressToBase64(byte[] message) throws IOException
//package com.java2s; //License from project: Open Source License import javax.xml.bind.DatatypeConverter; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.zip.GZIPOutputStream; public class Main { public static String compressToBase64(byte[] message) throws IOException { return DatatypeConverter.printBase64Binary(compress(message)); }/* w w w .j a va 2 s. com*/ public static byte[] compress(byte[] message) throws IOException { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); GZIPOutputStream gzipOut = new GZIPOutputStream(outputStream); gzipOut.write(message); gzipOut.finish(); byte[] result = outputStream.toByteArray(); gzipOut.close(); return result; } }