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
import java.io.*;
import java.util.zip.*;
public class Ex1 {
public static void main(String[] args) throws Exception{
String str ;
H h1 = new H();
h1.setHcfId("PH12345658");
h1.setHcfName("PANA HEALTH ACRE FACILITY");
str = h1.toString();
System.out.println(str);
if (str == null || str.length() == 0) {
return ;
}
ByteArrayOutputStream out = new ByteArrayOutputStream(str.length());
GZIPOutputStream gzip = new GZIPOutputStream(out);
gzip.write(str.getBytes());
gzip.close();
out.close();
String s = out.toString() ;
System.out.println( s );
byte[] ba = out.toByteArray();
System.out.println( "---------------BREAK-------------" );
ByteArrayInputStream in = new ByteArrayInputStream(ba);
GZIPInputStream gzis = new GZIPInputStream(in);
InputStreamReader reader = new InputStreamReader(gzis);
BufferedReader pr = new BufferedReader(reader);
String readed;
while ((readed = pr.readLine()) != null) {
System.out.println(readed);
}
//Close all the streams
}
}