Here you can find the source of compress(InputStream is, OutputStream os)
public static void compress(InputStream is, OutputStream os) throws Exception
//package com.java2s; import java.io.InputStream; import java.io.OutputStream; import java.util.zip.GZIPOutputStream; public class Main { static final int BUFFERSIZE = 1024; public static void compress(InputStream is, OutputStream os) throws Exception { GZIPOutputStream gos = new GZIPOutputStream(os); int count; byte data[] = new byte[BUFFERSIZE]; while ((count = is.read(data, 0, BUFFERSIZE)) != -1) { gos.write(data, 0, count);//from ww w . j a va 2 s. c o m } gos.flush(); gos.finish(); gos.close(); } }