Java Deflate Byte Array deflateGzip(final byte[] bts)

Here you can find the source of deflateGzip(final byte[] bts)

Description

deflate Gzip

License

Apache License

Declaration

public static final byte[] deflateGzip(final byte[] bts)
            throws IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

import java.util.zip.GZIPInputStream;

public class Main {
    public static final byte[] deflateGzip(final byte[] bts)
            throws IOException {
        final int buffLen = 2 * bts.length;
        final GZIPInputStream in = new GZIPInputStream(
                new ByteArrayInputStream(bts));
        final ByteArrayOutputStream out = new ByteArrayOutputStream(buffLen);
        int len = 0;
        final byte[] buff = new byte[buffLen];

        try {/*w  w  w. ja va 2  s .c o  m*/

            while ((len = in.read(buff)) > 0)
                out.write(buff, 0, len);

        } finally {
            in.close();
        }
        return out.toByteArray();
    }
}

Related

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