Here you can find the source of compress(ByteBuffer buffer)
static public byte[] compress(ByteBuffer buffer) throws Exception
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.ByteBuffer; import java.util.zip.GZIPOutputStream; public class Main { static public byte[] compress(ByteBuffer buffer) throws Exception { return compress(buffer.array()); }/* w w w . jav a 2s. com*/ static public byte[] compress(byte[] bytes) throws IOException { return compress(bytes, 0, bytes.length); } static public byte[] compress(byte[] bytes, int fromPos, int length) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(bytes.length / 4); GZIPOutputStream gzipOut = new GZIPOutputStream(bos); gzipOut.write(bytes, fromPos, length); gzipOut.close(); return bos.toByteArray(); } }