package com.saki.tools;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.InflaterInputStream;

public class Zip {
    public static final byte[] Deflater(byte[] bin) {
        try {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            DeflaterOutputStream os = new DeflaterOutputStream(bos);
            os.write(bin);
            os.finish();
            os.flush();
            return bos.toByteArray();
        } catch (IOException e) {
        }
        return null;
    }

    public static final byte[] Inflater(byte[] en) {
        try {
            ByteArrayInputStream in = new ByteArrayInputStream(en);
            InflaterInputStream iis = new InflaterInputStream(in);
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            int i = -1;
            while ((i = iis.read()) != -1) {
                os.write(i);
            }
            return os.toByteArray();
        } catch (IOException e) {
        }
        return null;
    }
}
