Java Deflate Byte Array deflater(final byte[] inputByte)

Here you can find the source of deflater(final byte[] inputByte)

Description

deflater

License

Open Source License

Declaration

public static byte[] deflater(final byte[] inputByte) throws IOException 

Method Source Code

//package com.java2s;
/**/*  w  w w. j a  va 2s .  com*/
 *
 * Licensed Property to China UnionPay Co., Ltd.
 * 
 * (C) Copyright of China UnionPay Co., Ltd. 2010
 *     All Rights Reserved.
 *
 * 
 * Modification History:
 * =============================================================================
 *   Author         Date          Description
 *   ------------ ---------- ---------------------------------------------------
 *   xshu       2014-05-28     ??????????????
 * =============================================================================
 */

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

import java.util.zip.Deflater;

public class Main {

    public static byte[] deflater(final byte[] inputByte) throws IOException {
        int compressedDataLength = 0;
        Deflater compresser = new Deflater();
        compresser.setInput(inputByte);
        compresser.finish();
        ByteArrayOutputStream o = new ByteArrayOutputStream(inputByte.length);
        byte[] result = new byte[1024];
        try {
            while (!compresser.finished()) {
                compressedDataLength = compresser.deflate(result);
                o.write(result, 0, compressedDataLength);
            }
        } finally {
            o.close();
        }
        compresser.end();
        return o.toByteArray();
    }
}

Related

  1. deflate(String text, String encode)
  2. deflateBuffer(byte[] uncompressedBuffer)
  3. deflateByteArray(final byte[] array)
  4. deflateGzip(byte[] inputBytes)
  5. deflateGzip(final byte[] bts)