Decodifica i byte da un InputStream, è possibile utilizzare un InputStreamReader. BufferedReader ti consentirà di leggere il tuo flusso riga per riga.
Se la zip è un file di testo
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);
}
Come notato nei commenti. Ignorerà la codifica e forse non funzionerà sempre correttamente.
soluzione migliore
Si scriverà i dati non compressi al 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();
Sono confuso, cioè solo un InputStream, lo si legge come qualsiasi altro InputStream. – njzk2
potresti anche confondere zip e gzip. – njzk2
Sì, il suo gzip not zip.I aggiornato. – Aajan