Java Gunzip Byte Array gunzip(final byte[] b, final Class c)

Here you can find the source of gunzip(final byte[] b, final Class c)

Description

return JSON form.

License

Open Source License

Parameter

Parameter Description
b gziped byte array.

Exception

Parameter Description
JSONException an exception
IOException an exception

Return

JSON string.

Declaration

public static final <T> T gunzip(final byte[] b, final Class<T> c) throws IOException 

Method Source Code

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

import java.io.ByteArrayInputStream;

import java.io.IOException;

import java.util.zip.GZIPInputStream;

import com.fasterxml.jackson.databind.ObjectMapper;

public class Main {
    private static final ObjectMapper MAPPER = new ObjectMapper();

    /**/*  w  w  w  . j  av  a  2 s  .  c  om*/
     * return JSON form.
     * @param b gziped byte array.
     * @return JSON string.
     * @throws JSONException
     * @throws IOException
     */
    public static final <T> T gunzip(final byte[] b, final Class<T> c) throws IOException {
        if (b == null) {
            return null;
        }
        try (final GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(b))) {
            return MAPPER.readValue(in, c);
        }
    }
}

Related

  1. gunzip(byte[] contentBytes)
  2. gunzip(byte[] data)
  3. gunzip(byte[] data)
  4. gunzip(byte[] data)
  5. gunzip(byte[] in)
  6. gunzip(final byte[] pInput)