Java Deflate Byte Array deflate(byte[] data)

Here you can find the source of deflate(byte[] data)

Description

deflate compression

License

Open Source License

Declaration

public static byte[] deflate(byte[] data) 

Method Source Code


//package com.java2s;

import java.io.ByteArrayOutputStream;

import java.util.zip.Deflater;

public class Main {
    /**//ww w.j  av  a2  s.  com
     * deflate compression
     * */
    public static byte[] deflate(byte[] data) {
        Deflater compresser = new Deflater();
        compresser.setLevel(Deflater.BEST_COMPRESSION);
        compresser.setInput(data);
        compresser.finish();
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        byte[] bytes = new byte[1024];
        compresser.deflate(bytes);
        while (!compresser.finished()) {
            bos.write(bytes, 0, compresser.deflate(bytes));
        }
        bytes = bos.toByteArray();
        return bytes;
    }
}

Related

  1. deflate(byte[] array)
  2. deflate(byte[] buf)
  3. deflate(byte[] bytes)
  4. deflate(byte[] data)
  5. deflate(byte[] data)
  6. deflate(byte[] data, byte[] dictionary)
  7. deflate(byte[] in)