集册 Java实例教程 gzip带镜头

gzip带镜头

欢马劈雪     最近更新时间:2020-01-02 10:19:05

548
gzip带镜头


import java.io.ByteArrayInputStream;
/* 
 来自 
*时 代 J a v a - N o w J a v a . c o m*/

import java.io.ByteArrayOutputStream;

import java.io.Closeable;

import java.io.IOException;

import java.io.InputStream;

import java.io.ObjectInputStream;

import java.io.ObjectOutputStream;

import java.io.OutputStream;

import java.io.Serializable;

import java.util.zip.GZIPInputStream;

import java.util.zip.GZIPOutputStream;

import java.util.zip.ZipInputStream;

import java.util.zip.ZipOutputStream;

/* 
*来 自
 nowjava.com
*/

public class Main{

    public static byte[] gzipWithLen(byte[] bytes) throws IOException {

        ByteArrayOutputStream baOut = null;

        GZIPOutputStream gzOut = null;

        try {

            baOut = new ByteArrayOutputStream();

            baOut.write(EncodeUtils.int2ByteArray(bytes.length), 0, 4);

            gzOut = new GZIPOutputStream(baOut);

            gzOut.write(bytes);

            gzOut.finish();

            gzOut.flush();

            return baOut.toByteArray();

        } finally {

            closeQuietly(gzOut);

            closeQuietly(baOut);

        }

    }

    public 
展开阅读全文