Decode bytes from an InputStream, you can use an InputStreamReader. A BufferedReader will allow you to read your stream line by line.
If the zip is a TextFile
ByteArrayInputStream bais = new ByteArrayInputStream(responseBytes);
GZIPInputStream gzis = new GZIPInputStream(bais);
InputStreamReader reader = new InputStreamReader(gzis);
BufferedReader in = new BufferedReader(reader);
String readed;
while ((readed = in.readLine()) != null) {
System.out.println(readed);
}
As noticed in the comments. It will ignore the encoding, and perhaps not work always properly.
Better Solution
It will write the uncompressed data to the destinationPath
FileInputStream fis = new FileInputStream(sourcePath);
FileOutputStream fos = new FileOutputStream(destinationPath);
GZIPInputStream gzis = new GZIPInputStream(fis);
byte[] buffer = new byte[1024];
int len = 0;
while ((len = gzis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
fos.close();
fis.close();
gzis.close();