使用GZIP压缩输入字节数组。
/* n o w j a v a . c o m */ //package com.nowjava; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.zip.GZIPOutputStream; import sun.misc.BASE64Decoder; public class Main { /** * Compresses the input byte array using GZIP. * * @param binaryInput Array of bytes that should be compressed. * @return Compressed bytes * @throws IOException */ public static byte[] gzip(byte[] binaryInput) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); GZIPOutputStream gzipOut = new GZIPOutputStream(baos); /* N o w J a v a . c o m - 时 代 Java 提供 */ gzipOut.write(binaryInput); gzipOut.finish(); gzipOut.close(); return baos.toByteArray(); } /** * Compresses the input BASE64 encoded byte array using GZIP. * * @param base64Input BASE64 encoded bytes that should be compressed * @return Compressed bytes * @exception IOException */ public static byte[] gzip(String base64Input)