Here you can find the source of getGZippedContent(byte[] content)
public static byte[] getGZippedContent(byte[] content) throws IOException
//package com.java2s; /*/* w ww .j av a 2 s .c o m*/ * Protorabbit * * Copyright (c) 2009 Greg Murray (protorabbit.org) * * Licensed under the MIT License: * * http://www.opensource.org/licenses/mit-license.php * */ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.zip.GZIPOutputStream; public class Main { public static byte[] getGZippedContent(byte[] content) throws IOException { byte[] gzippedContent = null; if (content != null) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ByteArrayInputStream bis = new ByteArrayInputStream(content); GZIPOutputStream out = new GZIPOutputStream(bos); byte[] buffer = new byte[1024]; int read; while ((read = bis.read(buffer)) > 0) { out.write(buffer, 0, read); } bis.close(); out.finish(); out.close(); gzippedContent = bos.toByteArray(); } return gzippedContent; } }