java.util.zip.GZIPInputStream

2010-03-21T00:00:00+09:00 Java

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();
    }
}

java.text.Normalizer java.util.Observer