All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.app.common.encrypt.GZip Maven / Gradle / Ivy

package com.app.common.encrypt;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

/**
 * @Description
 * @Author  
 * @Date
 **/
public class GZip {

    public GZip() {
    }

    public static byte[] zip(byte[] buf) {
        ByteArrayOutputStream outputStream = null;
        GZIPOutputStream gzipOutputStream = null;

        try {
            outputStream = new ByteArrayOutputStream();
            gzipOutputStream = new GZIPOutputStream(outputStream);
            gzipOutputStream.write(buf);
            gzipOutputStream.finish();
            byte[] var5 = outputStream.toByteArray();
            return var5;
        } catch (Exception var17) {
        } finally {
            try {
                gzipOutputStream.close();
            } catch (Exception var16) {
            }

            try {
                outputStream.close();
            } catch (Exception var15) {
            }

        }

        return null;
    }

    public static byte[] unzip(byte[] array) {
        ByteArrayInputStream inputStream = null;
        GZIPInputStream gzipInputStream = null;
        ByteArrayOutputStream outputStream = null;

        try {
            byte[] buf = new byte[1024];
            inputStream = new ByteArrayInputStream(array);
            gzipInputStream = new GZIPInputStream(inputStream);
            outputStream = new ByteArrayOutputStream();
            boolean var5 = true;

            int length;
            while((length = gzipInputStream.read(buf)) > 0) {
                outputStream.write(buf, 0, length);
            }

            byte[] var7 = outputStream.toByteArray();
            return var7;
        } catch (Exception var23) {
        } finally {
            try {
                gzipInputStream.close();
            } catch (IOException var22) {
            }

            try {
                inputStream.close();
            } catch (IOException var21) {
            }

            try {
                outputStream.close();
            } catch (IOException var20) {
            }

        }

        return null;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy