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

jaskell.util.ZipHelper Maven / Gradle / Ivy

Go to download

This is a utils library for java 8 project. It include parsec combinators and sql generators library.

There is a newer version: 2.9.2
Show newest version
package jaskell.util;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.DataFormatException;
import java.util.zip.Deflater;
import java.util.zip.Inflater;

public class ZipHelper {
    static public byte[] decompressByteArray(byte[] bytes, int buffer_szie) throws DataFormatException, IOException {
        ByteArrayOutputStream baos = null;
        Inflater iflr = new Inflater();
        iflr.setInput(bytes);
        baos = new ByteArrayOutputStream();
        byte[] tmp = new byte[buffer_szie];
        try{
            while(!iflr.finished()){
                int size = iflr.inflate(tmp);
                baos.write(tmp, 0, size);
            }
        } finally {
            baos.close();
        }
        return baos.toByteArray();
    }

    static public byte[] decompressByteArray(byte[] bytes)  throws DataFormatException, IOException {
        return decompressByteArray(bytes, 64);
    }

    static public byte[] compressByteArray(byte[] bytes, int buffer_size) throws DataFormatException, IOException {
        ByteArrayOutputStream baos = null;
        Deflater dflr = new Deflater();
        dflr.setInput(bytes);
        dflr.finish();
        baos = new ByteArrayOutputStream();

        byte[] tmp = new byte[buffer_size];
        try{
            while(!dflr.finished()){
                int size = dflr.deflate(tmp);
                baos.write(tmp, 0, size);
            }
        } finally {
            dflr.end();
            baos.close();
        }
        return baos.toByteArray();
    }

    static public byte[] compressByteArray(byte[] bytes) throws DataFormatException, IOException {
        return compressByteArray(bytes, 64);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy