I am attempting to convert the gzipped body of a HTTP response to plaintext. I\'ve taken the byte array of this response and converted it to a ByteArrayInputStream. I\'ve th
Use Apache Commons to convert GzipInputStream to byteArray.
import java.io.InputStream;
import java.util.zip.GZIPInputStream;
import org.apache.commons.io.IOUtils;
public static byte[] decompressContent(byte[] pByteArray) throws IOException {
GZIPInputStream gzipIn = null;
try {
gzipIn = new GZIPInputStream(new ByteArrayInputStream(pByteArray));
return IOUtils.toByteArray(gzipIn);
} finally {
if (gzipIn != null) {
gzipIn.close();
}
}
To convert byte array uncompressed content to String, do something like this :
String uncompressedContent = new String(decompressContent(inputStream));