Java Deflate Byte Array deflate(byte[] data)

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

Description

deflate

License

Open Source License

Declaration

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

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import java.util.zip.Deflater;

public class Main {
    public static byte[] deflate(byte[] data) throws IOException {
        Deflater deflater = new Deflater(Deflater.DEFAULT_COMPRESSION, true);
        deflater.setInput(data);//  w ww  . j  av a  2  s  .  c o  m

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream(
                data.length);

        deflater.finish();
        byte[] buffer = new byte[1024];
        while (!deflater.finished()) {
            int count = deflater.deflate(buffer);
            outputStream.write(buffer, 0, count);
        }
        outputStream.close();
        byte[] output = outputStream.toByteArray();

        deflater.end();

        return output;
    }
}

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)
  8. deflate(byte[] input)
  9. deflate(final byte[] pInput)