通过gzip算法压缩数据字节
//package com.nowjava; // from nowjava - 时代Java import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.zip.GZIPOutputStream; public class Main { /** * Compress data bytes by gzip algorithm * * @param data * @return compressed data * @throws IOException */ public static byte[] gzip(byte[] data) throws IOException { if (data == null) { return data;/*来自 时代Java - nowjava.com*/ } ByteArrayOutputStream out = new ByteArrayOutputStream(); GZIPOutputStream gos = null; try { gos = new GZIPOutputStream(out); gos.write(data); }