Here you can find the source of deflateGzip(byte[] inputBytes)
Parameter | Description |
---|---|
inputBytes | a gzip compressed byte array |
Parameter | Description |
---|---|
IOException | error in gzip input stream |
public static byte[] deflateGzip(byte[] inputBytes) throws IOException
//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 { /**/*from ww w . j a v a2 s . c o m*/ * The size of a chunk for a byte buffer. */ private static final int BYTE_BUFFER_CHUNK_SIZE = 4096; /** * Deflate a gzip byte array. * * @param inputBytes a gzip compressed byte array * @return a deflated byte array * @throws IOException error in gzip input stream */ public static byte[] deflateGzip(byte[] inputBytes) throws IOException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); try (GZIPInputStream gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(inputBytes))) { byte[] buffer = new byte[BYTE_BUFFER_CHUNK_SIZE]; while (gzipInputStream.available() == 1) { int size = gzipInputStream.read(buffer); if (size == -1) { break; } byteArrayOutputStream.write(buffer, 0, size); } return byteArrayOutputStream.toByteArray(); } } }