Java Ungzip Byte Array ungzipPayload(byte[] compressed)

Here you can find the source of ungzipPayload(byte[] compressed)

Description

ungzip Payload

License

Apache License

Declaration

public static String ungzipPayload(byte[] compressed) 

Method Source Code


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

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;

import java.io.IOException;
import java.io.InputStreamReader;

import java.util.zip.GZIPInputStream;

public class Main {
    public static String ungzipPayload(byte[] compressed) {
        try {//w  ww .  j a v  a 2 s  .co  m
            if ((compressed == null) || (compressed.length == 0)) {
                throw new RuntimeException("Null/empty compressed payload. is_null=" + (compressed == null));
            }

            final StringBuilder outStr = new StringBuilder();
            final GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(compressed));
            final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(gis, "UTF-8"));

            String line;
            while ((line = bufferedReader.readLine()) != null) {
                outStr.append(line);
            }

            return outStr.toString();
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    }
}

Related

  1. unGZip(byte[] data)
  2. ungzip(byte[] in)
  3. unGzip(byte[] str, String charset)
  4. ungzipBestEffort(byte[] in)
  5. ungzipBuffer(byte[] bufInput)