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: http://www.gnu.org/software/classpath/license.html

import java.io.ByteArrayOutputStream;

import java.io.IOException;

import java.util.zip.Deflater;

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

                byte[] buffer = new byte[1024];
                while (!deflater.finished()) {
                    int count = deflater.deflate(buffer);
                    out.write(buffer, 0, count);
                }
                return out.toByteArray();
            } finally {
                deflater.end();
            }
        }
    }
}

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)