java.util.zip.GZIPInputStream
JavaでAccept-Encoding: gzipを利用するメモ
import java.io.ByteArrayOutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.zip.GZIPInputStream;
public class Test {
public static void main(String[] args) throws Exception {
HttpURLConnection conn = (HttpURLConnection)new URL(
"http://blog.kinjouj.net"
).openConnection();
conn.setRequestProperty("Accept-Encoding", "gzip");
conn.connect();
GZIPInputStream gis = new GZIPInputStream(conn.getInputStream());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int i;
while((i = gis.read()) != -1) {
baos.write(i);
}
baos.flush();
baos.close();
System.out.println(new String(baos.toByteArray()));
gis.close();
conn.disconnect();
}
}